0

I have variables named var1, var2, ... var100 in data. How can I call them in a loop? I can loop over them and get the names as strings like this:

for (i in c(sprintf("data$var%s",seq(1,100)))) {
  print(paste0(i))
}

But this gives me only the strings, and does not call the variables.

jkortner
  • 549
  • 2
  • 8
  • 23

1 Answers1

0
for (i in c(sprintf("var%s",seq(1,100)))) {
  print(data[, i])
}
jkortner
  • 549
  • 2
  • 8
  • 23