2

How can I de-select a column named "(Intercept)" using dplyr::select and not using the column-index?

library(dplyr)
library(tibble)

tib<-tribble(~"(Intercept)",~b,
              80,3,
              80,4,
              80,4)

tib[,-1] # works

select(tib,eval(parse(("-(Intercept)")))) # does not work
select(tib,as.name(("-(Intercept)"))) # does not work 
select(tib,-"\(Intercept\)") # does not work

Thanks&kind regards

r.user.05apr
  • 4,939
  • 3
  • 18
  • 37

1 Answers1

4

We need to use backquotes

tib %>% 
    select(-`(Intercept)`)
tib %>% 
    select(`(Intercept)`)
akrun
  • 789,025
  • 32
  • 460
  • 575