简体   繁体   中英

Separating cbinded data.frames into the original data.frames in R

Suppose I only have access to a cbind ed data.frame r below. Because the variable names in the original data.frames before cbind ing are the same, is it possible to separate r into the original data.frames?

Note. This is just a toy example, a functional solution is appreciated.

# Original data.frames:

c1 <- data.frame(study.name = c(1,1,2,3), mod.s=c(3,3,1,2), mod.g=c(1,1,3,1))
c2 <- data.frame(study.name = c(1,1,2,3), mod.s=c(3,3,2,1), mod.g=c(1,2,3,2))

r <- cbind(c1, c2[-1]) # The only available cbined data.frame

If we are keeping it in a list and then cbind , there is a way of identification

lst1 <- list(c1, c2[-1])
r <- do.call(cbind, lst1)
split.default(r,  rep(seq_along(lst1), sapply(lst1, ncol)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM