eric lee <ericlee100 <at> gmail.com> writes: > > Hi, > > I'd like to merge the following list and data frame by matching the first > column in the data frame to the first number in each object of the list. > I'd also like the merged object to be a list. Any suggestions? Thanks. > > eric > > a <- list(c(1,11), c(2,12), c(3,13), c(4,14), c(5,16)) > > b <- data.frame(1:5, 51:55) >
Here is one idea: > a <- list(c(1,11), c(2,12), c(3,13), c(4,14), c(5,16)) > b <- data.frame(1:5, 51:55) > tmp <- merge(do.call("rbind", a), b, by=1) > split(as.matrix(tmp), row(tmp)) $`1` [1] 1 11 51 $`2` [1] 2 12 52 $`3` [1] 3 13 53 $`4` [1] 4 14 54 $`5` [1] 5 16 55 ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.