Maas James Dr (MED)
2011-Jan-19 08:31 UTC
[R] combining matrices from a list into a multidimensional array
I get some results back from running an iterative analysis in the form of a list of matrices. What I would like to do with this list is combine it such that all the similar components get combined into a multidimensional array. If possible I'd like to put results[[1]]$resultmean and results[[2]]$resultmean into a 3x3x2 array, and also put results[[1]]$resultsd and results[[2]]$resultsd in a separate 3x3x2 array. I'm sure this has been asked before, can someone point me in the right direction? Thanks J> results[[1]] [[1]]$resultmean [,1] [,2] [,3] [1,] 1.000000 0.768552 0.5743416 [2,] 1.307785 1.000000 0.7500699 [3,] 1.747145 1.340882 1.0000000 [[1]]$resultsd [,1] [,2] [,3] [1,] 0.00000000 0.05495972 0.03390511 [2,] 0.09326529 0.00000000 0.05718047 [3,] 0.10250638 0.10124427 0.00000000 [[2]] [[2]]$resultmean [,1] [,2] [,3] [1,] 1.000000 0.8280938 0.6170682 [2,] 1.213807 1.0000000 0.7472884 [3,] 1.631536 1.3479570 1.0000000 [[2]]$resultsd [,1] [,2] [,3] [1,] 0.00000000 0.05942645 0.05017175 [2,] 0.08719565 0.00000000 0.06344005 [3,] 0.13576301 0.11621178 0.00000000 ==============================Dr. Jim Maas University of East Anglia
Dennis Murphy
2011-Jan-19 09:59 UTC
[R] combining matrices from a list into a multidimensional array
Hi: Try this: lapply(results, function(x) array(unname(unlist(x)), c(3, 3, 2))) HTH, Dennis On Wed, Jan 19, 2011 at 12:31 AM, Maas James Dr (MED) <J.Maas@uea.ac.uk>wrote:> I get some results back from running an iterative analysis in the form of a > list of matrices. What I would like to do with this list is combine it such > that all the similar components get combined into a multidimensional array. > If possible I'd like to put results[[1]]$resultmean and > results[[2]]$resultmean into a 3x3x2 array, and also put > results[[1]]$resultsd and results[[2]]$resultsd in a separate 3x3x2 array. > I'm sure this has been asked before, can someone point me in the right > direction? > > Thanks > > J > > > results > [[1]] > [[1]]$resultmean > [,1] [,2] [,3] > [1,] 1.000000 0.768552 0.5743416 > [2,] 1.307785 1.000000 0.7500699 > [3,] 1.747145 1.340882 1.0000000 > > [[1]]$resultsd > [,1] [,2] [,3] > [1,] 0.00000000 0.05495972 0.03390511 > [2,] 0.09326529 0.00000000 0.05718047 > [3,] 0.10250638 0.10124427 0.00000000 > > > [[2]] > [[2]]$resultmean > [,1] [,2] [,3] > [1,] 1.000000 0.8280938 0.6170682 > [2,] 1.213807 1.0000000 0.7472884 > [3,] 1.631536 1.3479570 1.0000000 > > [[2]]$resultsd > [,1] [,2] [,3] > [1,] 0.00000000 0.05942645 0.05017175 > [2,] 0.08719565 0.00000000 0.06344005 > [3,] 0.13576301 0.11621178 0.00000000 > > ==============================> Dr. Jim Maas > University of East Anglia > > ______________________________________________ > 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. >[[alternative HTML version deleted]]