Dear R users... I have a list, "z", below. z<-list(matrix(c(11,11,9,0,0,0),3,2),matrix(c(10,10,10,1,1,1),3,2), matrix(c(7,10,1,1),2,2))> z[[1]] [,1] [,2] [1,] 11 0 [2,] 11 0 [3,] 9 0 [[2]] [,1] [,2] [1,] 10 1 [2,] 10 1 [3,] 10 1 [[3]] [,1] [,2] [1,] 7 1 [2,] 10 1>From the list, I need to remove duplicated rows based on the 1st column ineach "z" element, and then eventually make one matrix as followings; [,1] [,2] [1,] 11 0 <---- from z[1] [2,] 9 0 <---- from z[1] [3,] 10 1 <---- from z[2] [4,] 7 1 <---- from z[3] [5,] 10 1 <---- from z[3] Any comments will be greatly appreciated. Regards, Kathyrn Lord -- View this message in context: http://www.nabble.com/make-one-matirx-in-list-after-removing-duplicated-rows-tp24708937p24708937.html Sent from the R help mailing list archive at Nabble.com.
Jorge Ivan Velez
2009-Jul-28 22:29 UTC
[R] make one matirx in list after removing duplicated rows
Dear Kathryrn, Here is one way: unique(do.call(rbind,z)) See ?unique, ?do.call and ?rbind for more information. HTH, Jorge On Tue, Jul 28, 2009 at 6:21 PM, kathie <> wrote:> > Dear R users... > > > I have a list, "z", below. > > > z<-list(matrix(c(11,11,9,0,0,0),3,2),matrix(c(10,10,10,1,1,1),3,2), > matrix(c(7,10,1,1),2,2)) > > > z > [[1]] > [,1] [,2] > [1,] 11 0 > [2,] 11 0 > [3,] 9 0 > > [[2]] > [,1] [,2] > [1,] 10 1 > [2,] 10 1 > [3,] 10 1 > > [[3]] > [,1] [,2] > [1,] 7 1 > [2,] 10 1 > > > >From the list, I need to remove duplicated rows based on the 1st column in > each "z" element, and then eventually make one matrix as followings; > > [,1] [,2] > [1,] 11 0 <---- from z[1] > [2,] 9 0 <---- from z[1] > [3,] 10 1 <---- from z[2] > [4,] 7 1 <---- from z[3] > [5,] 10 1 <---- from z[3] > > Any comments will be greatly appreciated. > > Regards, > > Kathyrn Lord > > > > -- > View this message in context: > http://www.nabble.com/make-one-matirx-in-list-after-removing-duplicated-rows-tp24708937p24708937.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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]]
David Winsemius
2009-Jul-29 03:34 UTC
[R] make one matirx in list after removing duplicated rows
That did not actually deliver the requested results because it bound before it unique-ed. > unique(do.call(rbind,z)) [,1] [,2] [1,] 11 0 [2,] 9 0 [3,] 10 1 [4,] 7 1 I found it necessary to do a bit more list processing before the rbind: > do.call( rbind, lapply(z, function(x) x[!duplicated(x[,1]), ] ) ) [,1] [,2] [1,] 11 0 [2,] 9 0 [3,] 10 1 [4,] 7 1 [5,] 10 1 -- David Winsemius On Jul 28, 2009, at 6:29 PM, Jorge Ivan Velez wrote:> Dear Kathryrn, > Here is one way: > > unique(do.call(rbind,z)) > > See ?unique, ?do.call and ?rbind for more information. > > HTH, > > Jorge > > > On Tue, Jul 28, 2009 at 6:21 PM, kathie <> wrote: > >> >> Dear R users... >> >> >> I have a list, "z", below. >> >> >> z<-list(matrix(c(11,11,9,0,0,0),3,2),matrix(c(10,10,10,1,1,1),3,2), >> matrix(c(7,10,1,1),2,2)) >> >>> z >> [[1]] >> [,1] [,2] >> [1,] 11 0 >> [2,] 11 0 >> [3,] 9 0 >> >> [[2]] >> [,1] [,2] >> [1,] 10 1 >> [2,] 10 1 >> [3,] 10 1 >> >> [[3]] >> [,1] [,2] >> [1,] 7 1 >> [2,] 10 1 >> >> >>> From the list, I need to remove duplicated rows based on the 1st >>> column in >> each "z" element, and then eventually make one matrix as followings; >> >> [,1] [,2] >> [1,] 11 0 <---- from z[1] >> [2,] 9 0 <---- from z[1] >> [3,] 10 1 <---- from z[2] >> [4,] 7 1 <---- from z[3] >> [5,] 10 1 <---- from z[3] >> >> Any comments will be greatly appreciated. >> >> Regards, >> >> Kathyrn Lord >> >> >> >> -- >> View this message in context: >> http://www.nabble.com/make-one-matirx-in-list-after-removing-duplicated-rows-tp24708937p24708937.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help at 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]] > > ______________________________________________ > R-help at 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.David Winsemius, MD Heritage Laboratories West Hartford, CT