0

I have some sequentially labeled data frames i.e frame_1 frame_2 e.t.c... I would like to access them in a sequential manner possibly using a loop

one way that makes sense to me is to assign the name of the data frame I want to access to an object, then pass that object to a function i.e

varname<-paste("frame_",1,_sep="")

then call my function

function(varname)

But R appears to call the function on a string varname, and not the object with the same name as varname.

Is there way I can do what I want?

Thanks.

user124123
  • 1,642
  • 7
  • 30
  • 50

1 Answers1

1

I found out you can parse a string as an R command using a combination of eval and parse, so for instance :

   function( eval( parse(text=paste0("name_",1))) )

In a loop:

for( i in 1:length(holder)){
  function(eval( parse(text=paste0("frame_",i))) )
}
user124123
  • 1,642
  • 7
  • 30
  • 50
  • Just found this question/answer while looking for duplicates of a similar question. `eval(parse())` works for this, but is overkill. `get()` is simpler, but as Senor O said in comments using a list is considered best practice. – Gregor Thomas Oct 28 '15 at 15:53