I want to select columns from my tibble that end with the letter R AND do NOT start with a character string ("hc"). For instance, if I have a dataframe that looks like this:
name  hc_1  hc_2  hc_3r  hc_4r  lw_1r  lw_2  lw_3r  lw_4   
Joe   1     2     3      2      1      5     2      2
Barb  5     4     3      3      2      3     3      1
To do what I want, I've tried many options, but I'm surprised that this one doesn't work:
library(tidyverse)
data %>%
  select(ends_with("r"), !starts_with("hc"))
When I try it, I get this error:
Error:
!starts_with("hc")must evaluate to column positions or names, not a logical vector
I've also tried using negate() and get the same error.
library(tidyverse)
data %>%
  select(ends_with("r"), negate(starts_with("hc")))
Error:
negate(starts_with("hc"))must evaluate to column positions or names, not a function
I'd like to keep the answer within the dplyr select function because, once I select the variables, I'm going to end up reversing them by using mutate_at, so a tidy solution is best.
Thank you!
 
     
    