R – Converting a list of data frames into individual data frames in R

dataframefor-looplistr

I have been searching high and low for what I think is an easy solution.

I have a large data frame that I split by factors.

eqRegions <- split(eqDataAll, eqDataAll$SeismicRegion)

This now creates a list object of the data frames by region; there are 8 in total. I would like to loop through the list to make individual data frames using another name.

I can execute the following to convert the list items to individual data frames, but I am thinking that there is a loop mechanism that is fast if I have many factors.

testRegion1 <- eqRegions[[1]]

testRegion3 <- eqRegions[[3]]

I can manually perform the above and it handles it nicely, but if I have many regions it's not efficient. What I would like to do is the equivalent of the following:

for (i in 1:length(eqRegions)) {
   region[i] <- as.data.frame(eqRegions[[i]])
}

I think the key is to define region before the loop, but it keep overwriting itself and not incrementing. Many thanks.

Best Solution

Try

list2env(eqRegions,envir=.GlobalEnv)