每组计数观察/行数,并将结果添加到数据帧中
data.frame
df <- data.frame(name=c('black','black','black','red','red'), type=c('chair','chair','sofa','sofa','plate'), num=c(4,5,12,4,3))
name
type
table(df[ , c("name","type")])
plyr
df# name type num count# 1 black chair 4 2# 2 black chair 5 2# 3 black sofa 12 1 # 4 red sofa 4 1# 5 red plate 3 1
count
plyr
互换的青春
桃花长相依