标签:
如何对dataframe做group by ,需要使用data.frame table等等
http://stackoverflow.com/questions/25293045/count-number-of-rows-in-a-data-frame-in-r-based-on-group
mydf
# ID MONTH.YEAR VALUE
# 1 110 JAN. 2012 1000
# 2 111 JAN. 2012 2000
# 3 121 FEB. 2012 3000
# 4 131 FEB. 2012 4000
# 5 141 MAR. 2012 5000
Here‘s the calculation of the number of rows per group, in two output display formats:
table(mydf$MONTH.YEAR)
#
# FEB. 2012 JAN. 2012 MAR. 2012
# 2 2 1
data.frame(table(mydf$MONTH.YEAR))
# Var1 Freq
# 1 FEB. 2012 2
# 2 JAN. 2012 2
# 3 MAR. 2012 1
第一列升序,第二列降序
> a[order(a[,1],-a[,2]),]
[,1] [,2] [,3]
[1,] 2 7 14
[2,] 2 6 13
[3,] 3 8 10
[4,] 4 9 11
[5,] 5 6 12
标签:
原文地址:http://www.cnblogs.com/briller/p/4650971.html