Choose variables based on name (simple regular expression)

前端 未结 3 617
盖世英雄少女心
盖世英雄少女心 2020-12-30 13:03

I would like to incorporate variable names that imply what I should do with them. I imagine a dataframe \"survey\".

library(Rlab) # Needed for rbern() functi         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-30 13:33

    You can use grep() with colnames():

    survey[,grep("bern", colnames(survey))]
    

提交回复
热议问题