`tapply()` to return data frame

人盡茶涼 提交于 2019-12-04 12:03:48

You might try...

aggregate( c ~ node + date, data = data, FUN = mean )

If you want output that's a data frame with three columns, you probably would benefit from looking at the plyr package (assuming your data are stored in dat):

library(plyr)
ddply(dat,.(date,node),summarise,m = mean(c))

Instead of tapply you want to use ave

data$grp.mean <- ave(data$c, list(data$node, data$date), FUN= mean)

Looking again at this I am wondering if you wanted to have the aggregation done on the basis of "date" in the calendar sense of 24 hours?

If you wanted to use the results you already have (assuming they are named "M") you might want to try :

require(reshape2)
newdf <- melt(t(M))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!