我正在以多种方式聚合多个变量,并且必须以非常笨重的方式重命名。如果我可以重命名所有内容会更简单,但我的分组列(在这种情况下为日期)每次都会重命名,并且最后不会合并。
df <- group_by(df, date)
sums <- df%>%
summarise_each(funs(sum), v1, v2, v3)
names(sums)[2:length(sums)] <- paste0(names(sums)[2:length(sums)], "_sum")
means <- df%>%
summarise_each(funs(mean))
names(means)[2:length(means)] <- paste0(names(means)[2:length(means)], "_mean")
maxs <- df%>%
summarise_each(funs(max), v45, v46, v47)
names(maxs)[2:length(maxs)] <- paste0(names(maxs)[2:length(maxs)], "_max")
text.stats <- Reduce(function(...) merge(..., by = 'date', all=TRUE), list(sums, means, maxs))
有关如何清理它的任何想法?当调用多个函数时,或许强制summarise_each()的行为附加变量名?