1

I have a bunch of objects in the R environment which I want to call them in a loop.

assume x1, x2, x3, x4 are data frames in R environment, and NAME_0 is a column in all of the dfs.

What I am aiming to do is:

for (i i 1:4) {
  print(unique(paste0('x',i)$NAME_0)
}

I get an error: object of type 'symbol' is not subsettable

I am not sure how to circumvent this!?

  • 2
    Use `get()` to turn a string in the value of the variable of the same name. For example `print(unique(get(paste0('x',i))$NAME_0))` – MrFlick Jul 22 '20 at 22:43

0 Answers0