Choose variables based on name (simple regular expression)

前端 未结 3 627
盖世英雄少女心
盖世英雄少女心 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:25

    The "operators" package allows some Perl-like syntax:

    library(operators)
    
    survey[, colnames(survey) %~% "bern"]
    

    or

    subset(survey, select = colnames(survey) %~% "bern")
    

提交回复
热议问题