1

虽然是 dplyr 的狂热粉丝,但我仍然对在尝试做一些非常复杂的事情时不可避免地出现的一些 NSE 问题感到困惑。

恰当的例子:查找列子集的行总和。

temp <- data.frame(A = 1:3, B = 4:6, C = 8:10)

这有效:

temp %>% {rowSums(select(., B:C), na.rm = TRUE)}

这个(SE版本)有效:

temp %>% mutate(Sum = rowSums(select_(., .dots = "B:C"), na.rm = TRUE))

但这不起作用:

temp %>% mutate(Sum = rowSums(select(., B:C), na.rm = TRUE))

Error: Position must be between 0 and n
In addition: Warning messages:
1: In 4:6:8:10 : numerical expression has 3 elements: only the first used
2: In 4:6:8:10 : numerical expression has 3 elements: only the first used

为什么?

4

0 回答 0