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!?

1
  • 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)) Commented Jul 22, 2020 at 22:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.