How does one aggregate and summarize data quickly?

前端 未结 2 947
别跟我提以往
别跟我提以往 2020-12-29 08:05

I have a dataset whose headers look like so:

PID Time Site Rep Count

I want sum the Count by Rep for each P

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 08:57

    You should look at the package data.table for faster aggregation operations on large data frames. For your problem, the solution would look like:

    library(data.table)
    data_t = data.table(data_tab)
    ans = data_t[,list(A = sum(count), B = mean(count)), by = 'PID,Time,Site']
    

提交回复
热议问题