data.table 방식으로 열 계산하기

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
R의 data.table로 데이터 조작하기

행과 열 계산하기

ij를 결합하는 것은 간단합니다

# Compute mean of duration column for "Japantown" start station
batrips[start_station == "Japantown", mean(duration)]
2464.331
R의 data.table로 데이터 조작하기

j에서의 특수 기호 .N

  • .Nj에서도 사용 가능합니다
  • 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로 데이터 조작하기

연습해 봅시다!

R의 data.table로 데이터 조작하기

Preparing Video For Download...