R, DataFrame - group by multiple rows -
i have data.frame posts looks this:
post_id group_id hour(when posted) likes 1 1 13 5 2 1 13 6 3 1 23 3 4 2 12 30 5 2 13 34 6 2 22 10 i want plot likes distribution hours in each group, need data.frame one:
0 ... 12 13 ... 22 23 <- hours gorup#1 0 11 3 <- sum of likes in group#i in xx hour group#2 30 34 10 0 how can group post group , hour?
assuming data.frame called "mydf", perhaps can try xtabs (since you're looking sum):
> xtabs(likes ~ group_id + hour, mydf) hour group_id 12 13 22 23 1 0 11 0 3 2 30 34 10 0 to levels "hour", if sum "0" groups, factor "hour" column first.
another convenient alternative use dcast "reshape2" package.
Comments
Post a Comment