How to apply summarise_each to all columns except one? [duplicate]

匿名 (未验证) 提交于 2019-12-03 03:12:02

问题:

This question already has an answer here:

I am analyzing a set of data with many columns (almost 30 columns). I want to group data based on two columns and apply sum and mean functions to all the columns except timestamp. How would I use summarise_each on all columns except timestamp?

This is the draft code I have but it obviously not correct. Plus it generates and error because it can not apply Sum to POSIXt data type (Error: 'sum' not defined for "POSIXt" objects)

features <- dataset %>%    group_by(X, Y) %>%    summarise_each(funs(mean,sum)) %>%   arrange(TIMESTAMP)

回答1:

Try summarise_each(funs(mean,sum), -TIMESTAMP) to exclude TIMESTAMP from the summarisation.



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