0

I am trying to create a table one using the TableOne package where I have specify my variables that will be stratified. Is there a way in R to specify a list of columns if they have standardized naming convention. I.e my columns go c01, c02 all the way to c64? i.e. can i do something like vars="c01-c64" in the Table One package.

zx8754
  • 52,746
  • 12
  • 114
  • 209
RoV
  • 13
  • 3
  • Related possible duplicate post: https://stackoverflow.com/q/5812493/680068 – zx8754 Jan 31 '21 at 22:59
  • TableOne has "vars" argument, use above post to create zero prefixed vector. – zx8754 Jan 31 '21 at 23:00
  • There are lots of ways to do this. For you example you can filter with "c %in% vars" to get the colnames with "c" in them. Check out the {stringr} and {stringi} packages for more details. – bstrain Jan 31 '21 at 23:04

1 Answers1

0

Solved

list <-df[,grep("c", colnames(df))] %>% colnames()
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
RoV
  • 13
  • 3