I'm trying to loop through several data frames that all have a standard name other than the last character which is an integer. I am trying to loop through the data frames and perform a task on each but I don't know how to reference each data frame by name.
for(i in 1:length(xyz)){
approx(df & i & $X, df & i & $Y, xout=aim)
}
that is essentially the format I want where each iteration will increase the number i and therefore the name of the data frame eg. df1$X, df2$X, df3$X, df4$X...
I know this code won't work but I don't know what will
lst1 <- mget(ls(pattern = 'df[0-9]+')); lapply(lst1, function(i) approx(i$X, ...))
) - Sotosapprox(eval(parse(text = paste0("df", i, "$X"))), eval(parse(text = paste0("df", i, "$Y"))), xout = aim)
. But listen to @Sotos and use a list. - LAPmget(ls(...))
will put all your data.frames in a list calledlst1
. Afterwards you apply the functionfunction(i) approx(i$X, i$Y, xout = aim)
over the list of your data.frames with thelapply()
call and either print the output, or save it to another list by assigningoutput <- lapply(...)
. - LAP