You might want to store the data frames in a list to eliminate this
problem and make it more convenient to iterate over them:
L <- list(df1 = df1, df2 = df2)
rm(df1, df2)
# reduce each data frame to its first few rows
for(nm in names(L)) L[[nm]] <- head(L[[nm])
or if you don't need to modify t
One way to do it is to pass in the character name of the dataframe you
want to reference and then use 'get' to access the value: e.g.,
df1 <- data.frame(x=seq(0,10), y=seq(10,20))
df2 <- data.frame(a=seq(0,10), b=seq(10,20))
# use the character names for referencing
for (df in c('df1', 'df2')){
I have several data frames, eg:
> df1 <- data.frame(x=seq(0,10), y=seq(10,20))
> df2 <- data.frame(a=seq(0,10), b=seq(10,20))
It is common to create loops in R like this:
> for(df in list(df1, df2)){ #etc. }
This works fine when you know the name of the objects to put into the
list. I assume