【问题标题】:Summing several columns and keep the summed value only对几列求和并仅保留总和值
【发布时间】:2017-02-18 22:17:44
【问题描述】:

我正在使用iris 练习数据操作。我试图将Sepal.WidthPetal.Width 加到一列。我提到了这个问题In R, how to replace values in multiple columns with a vector of values equal to the same width?

得到了总和,但 Sepal.WidthPetal.Width 没有被删除。请帮忙。非常感谢。

我的代码是

iris <- iris %>% mutate(rowSums(iris[,c(2,4)]))

【问题讨论】:

    标签: r dplyr


    【解决方案1】:

    使用原生的dplyr 方式对列求和,并在?mutateUse NULL to drop a variable. 中指定:

    iris %>% 
        mutate(Sepal.Length + Petal.Length, Sepal.Length = NULL, Petal.Length = NULL)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-17
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      相关资源
      最近更新 更多