【发布时间】:2021-05-12 16:28:11
【问题描述】:
我有一个虹膜,我需要将每个虹膜除以相应列的总和。所以我正在考虑使用 mutate 以便所有操作立即发生。但我越来越错误了
iris1 <- head(iris[1:4])
iris1 %>% mutate(across(c(1:4), ~.-colSums(.)))
Error: Problem with `mutate()` input `..1`.
x 'x' must be an array of at least two dimensions
ℹ Input `..1` is `across(c(1:4), ~. - colSums(.))`.
Run `rlang::last_error()` to see where the error occurred.
预期(因为 29.7 是 1 列的总和。其他列类似)
Sepal.Length Sepal.Width Petal.Length Petal.Width
1 5.1/29.7 3.5 1.4 0.2
2 4.9/29.7 3.0 1.4 0.2
3 4.7/29.7 3.2 1.3 0.2
4 4.6/29.7 3.1 1.5 0.2
5 5.0/29.7 3.6 1.4 0.2
6 5.4/29.7 3.9 1.7 0.4
【问题讨论】:
标签: r