Select (dplyr) operator with '-'

How do I use a SELECT (dplyr library) statement with a name containing '-'? For example:

AdultUCI %>% select(capital-gain) 

      

called:

error

+3
r dplyr


source to share


2 answers


try it



data.frame(`a-b` = 1, c = 2, check.names = FALSE) %>% 
  select(`a-b`)
#   a-b
# 1   1

      

+8


source to share


We can use matches

insideselect



data.frame(`a-b` = 1, c = 2, check.names = FALSE) %>% 
         select(matches('-'))
#    a-b
# 1   1

      

+2


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics