[R] how to collapse a list of 1 column matrix to a matrix?
adschai at optonline.net
adschai at optonline.net
Mon Aug 20 07:13:09 CEST 2007
Thank you. I found the same answer.
----- Original Message -----From: Jared O'Connell Date: Sunday, August 19, 2007 9:56 pmSubject: Re: [R] how to collapse a list of 1 column matrix to a matrix?To: "adschai at optonline.net" Cc: r-help at stat.math.ethz.ch> > x = matrix(rnorm(9),3)> > x> [,1] [,2] [,3]> [1,] 1.29693748 0.2018959 0.02534092> [2,] -1.19468858 -1.2249229 -0.85948508> [3,] -0.09274508 0.4071841 -0.11481410> > apply(x,1,which.min)> [1] 3 2 3> > > > On 8/20/07, adschai at optonline.net wrote:> >> > One more question. After I collapse everything into one > matrix, I would> > like to find the index of column that holds minimum value for > each row. I> > remember that there is a function like maxCols but I can't > seem to find the> > same thing for minimum value. Any suggestion please?> >> > - adschai> >> >> > ----- Original Message -----From: Gabor Grothendieck Date: > Sunday, August> > 19, 2007 8:48 pmSubject: Re: [R] how to collapse a list of 1 > column matrix> > to a matrix?To: "adschai at optonline.net" Cc: r-> help at stat.math.ethz.ch> Try> > this:> > L <- list(`1` = matrix(1:4, 4), `2` = matrix(5:8, > 4))> sapply(L,> > c)> > Note that the list component names are kept as column > names in > the> > result> > > On 8/19/07, adschai at optonline.net wrote:> > Hi,> > >> > I> > encounter a situation where I have a list whose element is a > > column> matrix. Says,> >> > $'1'> > [,1]> > 1> > 2> > 3> >> > > $'2'> > [,1]> > 4> >> > 5> > 6> >> > Is there fast way to collapse the list into a > matrix like a >> > cbind operation in this case? Meaning, the result should be a > > matrix that> > looks like:> >> > [,1] [,2]> > [1,] 1 4> > [2,] > 2 5> >> > [3,] 3 6> >> > I can loop through all elements and do cbind> > manually. But I > think there must be a simpler way that I > don't know. Thank> > you.> >> > - adschai> >> > __!> > ____________________________________________> > R-> help at stat.math.ethz.chmailing 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.> >>> >> > ______________________________________________> > R-help at stat.math.ethz.ch 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.> >>
More information about the R-help
mailing list