I have 8,000 data.frame
s inside my global environment (.GlobalEnv
) in R, for example
head(ls(.GlobalEnv))
#[1] \"db1\" \"db2\" \"db3\"
You could use a combination of eapply
and mget
to put all data.frame
s that are present in the global environment in a list
:
x <- eapply(.GlobalEnv, 'is.data.frame')
dflist <- mget(names(x[unlist(x)]), .GlobalEnv)
Then you can use for example lapply(dflist, ...)
to run a regression on each of them.
A very concise alternative approach contributed by @RichardScriven in the comments is:
dflist <- Filter(is.data.frame, as.list(.GlobalEnv))