如何在R中选择带有星号的变量

I want to select some variables from my csv file in R. I used this select(gender*, age*), but got the error - object not found. I tried select(`gender*`, `age*`) and select(starts_with(gender), starts_with(age)), but neither works. Does anyone know how to select variables with star symbols? Thanks a lot!

评论
  • adicta
    adicta 回复

    It is possible that the select from dplyr is masked by select from any other package as this is working fine. Either specify the packagename with :: or do this on a fresh R session with only dplyr loaded

    library(dplyr)
    data(iris)
    iris$'gender*' <- 'M'
    iris%>% 
          head %>% 
          dplyr::select(`gender*`)
    #   gender*
    #1       M
    #2       M
    #3       M
    #4       M
    #5       M
    #6       M