[R] looping through data frames in a workspace

Martin Elff elff at sowi.uni-mannheim.de
Tue Mar 4 10:10:31 CET 2008


On Monday 03 March 2008 (23:28:05), lucy b wrote:
> I would like to avoid having to type-out a very long list over and
> over again. I have tried every variation I could think of similar to:
>
> for(df in list(noquote(ls()))) {
>
>      do stuff with df
>
>      }
>
> I know this has to be possible. What am I missing?

I guess something like the following will do what you want,
but I am not completely sure ...

for(dfname in ls()){
 eval(substitute({
		<do stuff with df>
		},
      		list(
		  df=as.name(dfname)
		  )
     		)
      )
	
}

HTH,
Martin



More information about the R-help mailing list