Groupby bins and aggregate in R
问题 I have data like (a,b,c) a b c 1 2 1 2 3 1 9 2 2 1 6 2 where 'a' range is divided into n (say 3) equal parts and aggregate function calculates b values (say max) and grouped by at 'c' also. So the output looks like a_bin b_m(c=1) b_m(c=2) 1-3 3 6 4-6 NaN NaN 7-9 NaN 2 Which is MxN where M=number of a bins, N=unique c samples or all range How do I approach this? Can any R package help me through? 回答1: There would be easier ways. If your dataset is dat res <- sapply(split(dat[, -3], dat$c),