R의 data.table로 데이터 조작하기
Matt Dowle, Arun Srinivasan
Instructors, DataCamp
열을 변수로 참조할 수 있으므로, 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
i와 j를 결합하는 것은 간단합니다
# Compute mean of duration column for "Japantown" start station
batrips[start_station == "Japantown", mean(duration)]
2464.331
.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
R의 data.table로 데이터 조작하기