Manipularea datelor cu data.table în R
Matt Dowle, Arun Srinivasan
Instructors, DataCamp
Deoarece coloanele pot fi referite ca variabile, puteți calcula direct pe ele în j
# Compute mean of duration column using the data.table way
ans <- batrips[, mean(duration)]
1131.967
# Compute mean of duration column using the data.frame way
ans <- mean(batrips[, "duration"])
1131.967
Combinarea i și j este simplă
# Compute mean of duration column for "Japantown" start station
batrips[start_station == "Japantown", mean(duration)]
2464.331
.N poate fi utilizat și în j i# How many trips started from "Japantown"?
batrips[start_station == "Japantown", .N]
902
# Compare this to the data.frame way
nrow(batrips[batrips$start_station == "Japantown", ])
902
Manipularea datelor cu data.table în R