How to extract columns from dataframe using the column names and matching a part of the name

I am trying to use this dplyr function to extract the columns from a dataframe if the variable contains AverageValue as part of the column name. For example “eosinophilsAverageValue, but I get he message: Error in select(., contains("AverageValue")) : unused argument (contains("AverageValue")). I do not understand what might be going on because I think I am using the correct expression. Could you please help me with this?

dfa <- df %>% select(contains("AverageValue"))

Thank you

That's very interesting. Would you mind posting some sample data that people could test on? With made-up data (Which may not match your data structure), it looks like it is working for me.


df <- tibble(a = 1:3, eosinophilsAverageValue = 3:5)

 df %>% 
#> # A tibble: 3 x 1
#>   eosinophilsAverageValue
#>                     <int>
#> 1                       3
#> 2                       4
#> 3                       5

Created on 2021-10-05 by the reprex package (v2.0.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.