虽然是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
为什么?