0

I am constructing an RShiny app and am trying to generate the checkboxGroupInput options in an efficient manner.

I'd like to create a vector with every odd column name to avoid doing the below to generate the potential options for the user to select:

checkboxGroupInput("names","Names",c(colnames(df)[ncol(df)],colnames(df)[ncol(df)-2],colnames(df)[ncol(df)-4],etc...))

Is there a way to extract column names with a function like seq or letters? Ideally it would be something like, though of course the below does not work:

vector=c(colnames(Runs)[ncol(Runs)]:colnames(Runs)[3],-2)

Then I'd want to just insert that vector into the checkbox field.

Thanks for your help!

Z_D
  • 797
  • 2
  • 12
  • 30

1 Answers1

0

You can proceed with seq setting a negative by :

colnames(df)[seq(from = ncol(df), to = 1, by = -2)]

(It's not related to shiny though.)

Julien Navarre
  • 7,653
  • 3
  • 42
  • 69