Search code examples
rcbind

Assign the results of do.call using cbind to data frames


I want to combine multiple sets of two data frames (a & a_1, b & b_1, etc.). Basically, I want to do what this question is asking. I created a list of my two data sets:

# create data 
a <- c(1, 2, 3)
b <- c(2, 3, 4)
at0H0 <- data.frame(a, b)

c <- c(1, 2, 3)
d <- c(2, 3, 4)
at0H0_1 <- data.frame(c, d)

e <- c(1, 2, 3)
f <- c(2, 3, 4)
at0H1 <- data.frame(a, b)

g <- c(1, 2, 3)
h <- c(2, 3, 4)
at0H1_1 <- data.frame(c, d)

# create lists of names
names <- list("at0H0", "at0H1")
namesLPC <- list("at0H0_1", "at0H1_1")

# column bind the data frames?
dfList <- list(cbind(names, namesLPC))
do.call(cbind, dfList)

But now I need it to create data frames for each. This do.call function just creates a list of the names of the data frames. Thanks!

(Edited to make reproducible code)


Solution

  • I've figured out a way to do it. A few notes: I have 360 data sets that I need to combine, which is why it is i in 1:360. This also names the data sets from an array of the names of the data sets (which is dataNames)

    for (i in 1:360){
      assign(paste(dataNames[i], sep = ""), cbind(names[[i]], namesLPC[[i]]))
    }