【发布时间】:2015-05-06 18:44:00
【问题描述】:
我有一个这样的数据框
> df
Source: local data frame [4 x 4]
a x y z
1 name1 1 1 1
2 name2 1 1 1
3 name3 1 1 1
4 name4 1 1 1
想要通过添加列 x、y 和 z 来改变它(可以有更多的数字列)。尝试按如下方式排除“a”列是行不通的。
dft <- df %>% mutate(funs(total = rowSums(.)), -a)
Error: not compatible with STRSXP
这也会产生错误:
dft <- df %>% mutate(total = rowSums(.), -a)
Error in rowSums(.) : 'x' must be numeric
什么是正确的方法?
【问题讨论】: