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


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


We can use matches

insideselect



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

      

+2


source







All Articles