[R] [SPAM?] binding two lists of lists of dataframes together

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Tue May 12 00:08:54 CEST 2015


HTML email does not work at all well on this mailing list. Sending you your question in plain text will help, as will following the advice in [1] to use the dput function to format the data so that we can easily put it into R and know what you are working with.

My guess at your goal is that you are trying to make one long list out of two short ones. Why not just use the c() function to concatenate the lists? E.g.

List12 <- c( List1, List2 )

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example 
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On May 11, 2015 1:16:40 PM PDT, Vin Cheng <newrnewbie at hotmail.com> wrote:
> Hi, 
>I'm new to R and am stumped.  I'm trying to bind List 1 to List 2 and
>have the corresponding Output.  
> 
>I've found the following code - I can't say I understand
>rbindlist(lapply(list12, "[", i, TRUE)).  Either way - it doesn't give
>exactly what's needed.
> 
>library(data.table)
>list12 <- list(List1,List2)
>nr <- as.vector(nrow(list12[[1]]))
>fastbind.ith.rows <- function(i) rbindlist(lapply(list12, "[", i,
>TRUE))
>fastbound <- lapply(1:nr, fastbind.ith.rows)
> 
>It produces Output 2 - where dataframes are grouped together by
>rownames, but keeps 2 separate vectors - vs. binding the two into 1
>vector.
> 
>Any help/guidance would be greatly appreciated!!
> 
>Thanks!
>Vince
> 
> 
>List1List2Output (Wanted) V1V2V3 V1V2V3
>V1V2V3idc(563,623,581)c(563,623,581)c(563,623,581)idc(217,  120,
>372)c(125,  334, 86)c(130,  349, 576)idc(563,623,581,217,  120,
>372)c(563,623,581,125,  334, 86)c(563,623,581,130,  349,
>576)wgtbandc(0,  0, 0, 0, 0)c(0,  0, 0, 0, 0)c(0,  0, 0, 0,
>0)wgtbandc(1,  2, 3)c(1,  2, 3)c(1,  2, 3)wgtbandc(0,  0, 0, 0, 0,1, 2,
>3)c(0,  0, 0, 0, 0,1, 2, 3)c(0,  0, 0, 0, 0,1, 2, 3)wgtc(0.007956164, 
>0.00199414, 0.009970699, 0.00994571, 0.011994826)c(0.007956164, 
>0.00199414, 0.009970699, 0.00994571, 0.011994826)c(0.007956164, 
>0.00199414, 0.009970699, 0.00994571, 0.011994826)wgtc(0.003565190625, 
>0.003565190625, 0.003565190625)c(0.003565190625,  0.00514971979166667,
>0.003565190625)c(0.003565190625,  0.003565190625,
>0.00514971979166667)wgtc(0.007956164,  0.00199414, 0.009970699,
>0.00994571, 0.011994826,0.003565190625,  0.003565190625,
>0.003565190625)c(0.007956164,  0.00199414, 0.009970699, 0.00994571,
>0.011994826,0.003565190625,  0.00514971979166667,!
> 
> 
>0.003565190625)c(0.007956164,  0.00199414, 0.009970699, 0.00994571,
>0.011994826,0.003565190625,  0.003565190625,
>0.00514971979166667)heldc(2,  2, 2, 2, 2)c(2,  2, 2, 2, 2)c(2,  2, 2,
>2, 2)heldc(0,  0, 0)c(0,  0, 0)c(0,  0, 0)heldc(2,  2, 2, 2, 2,0, 0,
>0)c(2,  2, 2, 2, 2,0, 0, 0)c(2,  2, 2, 2, 2,0, 0, 0)efficiencyc(765, 
>1660, 1539, 1377, 1452)c(765,  1660, 1539, 1377, 1452)c(765,  1660,
>1539, 1377, 1452)efficiencyc(1292,  908, 1283)c(1292,  908,
>1283)c(1292,  908, 1283)efficiencyc(765,  1660, 1539, 1377, 1452,1292,
>908, 1283)c(765,  1660, 1539, 1377, 1452,1292, 908, 1283)c(765,  1660,
>1539, 1377, 1452,1292, 908, 1283)couponc(4,  11, 16, 27, 48)c(4,  11,
>16, 27, 48)c(4,  11, 16, 27, 48)couponc(735,  403, 1366)c(414,  1183,
>284)c(435,  1222, 127)couponc(4,  11, 16, 27, 48,735, 403, 1366)c(4, 
>11, 16, 27, 48,414, 1183, 284)c(4,  11, 16, 27, 48,435, 1222, 127) 
>Output2 from Sample Code
>V1V2V3idc(563,623,581)c(563,623,581)c(563,623,581)c(217, 120,
>372)c(125,  334, 86)c(130,  349, 576)wgtbandc(0,  0, 0, 0, 0)c(0,  0,
>0, 0, 0)c(0,  0, 0, 0, 0)c(1, 2, 3)c(1,  2, 3)c(1,  2,
>3)wgtc(0.007956164,  0.00199414, 0.009970699, 0.00994571,
>0.011994826)c(0.007956164,  0.00199414, 0.009970699, 0.00994571,
>0.011994826)c(0.007956164,  0.00199414, 0.009970699, 0.00994571,
>0.011994826)c(0.003565190625, 0.003565190625, 
>0.003565190625)c(0.003565190625,  0.00514971979166667,
>0.003565190625)c(0.003565190625,  0.003565190625,
>0.00514971979166667)heldc(2,  2, 2, 2, 2)c(2,  2, 2, 2, 2)c(2,  2, 2,
>2, 2)c(0, 0, 0)c(0,  0, 0)c(0,  0, 0)efficiencyc(765,  1660, 1539,
>1377, 1452)c(765,  1660, 1539, 1377, 1452)c(765,  1660, 1539, 1377,
>1452)c(1292, 908, 1283)c(1292,  908, 1283)c(1292,  908, 1283)couponc(4,
>11, 16, 27, 48)c(4,  11, 16, 27, 48)c(4,  11, 16, 27, 48)c(735, 403,
>1366)c(414,  1183, 284)c(435,  1222, 127) 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>
> 		 	   		  
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.



More information about the R-help mailing list