如何将summarise_each应用于除一列之外的所有列? [英] How to apply summarise_each to all columns except one?

查看:58
本文介绍了如何将summarise_each应用于除一列之外的所有列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在分析一组包含许多列(将近30列)的数据。我想基于两列对数据进行分组,并对除时间戳以外的所有列应用求和和均值函数。
我如何在除时间戳之外的所有列上使用summarise_each?

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?

这是我的草稿代码,但显然不正确。加上它会产生错误,因为它无法将Sum应用于POSIXt数据类型(错误:未为 POSIXt对象定义 sum)

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)


推荐答案

尝试 summarise_each(funs (平均值,总和,-TIMESTAMP)从摘要中排除 TIMESTAMP

这篇关于如何将summarise_each应用于除一列之外的所有列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆