1

While an avid fan of dplyr, I'm still puzzled by some of the NSE issues that inevitably arise when I try to do something of non-trivial complexity.

Case in point: finding row sums of a subset of columns.

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

This works:

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

and this (SE version) works:

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

but this does not work:

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

Why?

Axeman
  • 32,068
  • 8
  • 81
  • 94
Victor Kostyuk
  • 621
  • 5
  • 16

0 Answers0