how can i tell select() in dplyr that the string it is seeing is a column name in a data frame

后端 未结 8 792
感动是毒
感动是毒 2020-12-24 11:15

I tried searching but didn\'t find an answer to this question.

I\'m trying to use the select statement in dplyr but am having problems when I try to send it strings

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 11:30

    Select seems to work with the column indexes (dplyr 0.2), so just match your desired names to their index and use them to select the columns.

    myCols <- c("mpg","disp")
    colNums <- match(myCols,names(mtcars))
    mtcars %>% select(colNums)
    

提交回复
热议问题