Is there a way to create a new matrix from and existing matrix with A [,1] [,2] [1,] 1 13 [2.] 2 18 [3,] 3 14 [4,] 4 20 if(A[,2] > 15) B [,1] [,2] [1,] 2 18 [2,] 4 20 -- View this message in context: http://r.789695.n4.nabble.com/manipulating-a-matrix-tp2196610p2196610.html Sent from the R help mailing list archive at Nabble.com.
Try: A[A[,2] > 15,] On Wed, May 12, 2010 at 4:14 PM, Clark Johnston <clarkstat@clarktx.com>wrote:> > Is there a way to create a new matrix from and existing matrix with > > A > [,1] [,2] > [1,] 1 13 > [2.] 2 18 > [3,] 3 14 > [4,] 4 20 > > if(A[,2] > 15) > > B > [,1] [,2] > [1,] 2 18 > [2,] 4 20 > > > -- > View this message in context: > http://r.789695.n4.nabble.com/manipulating-a-matrix-tp2196610p2196610.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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Clark Johnston wrote:> Is there a way to create a new matrix from and existing matrix with > > A > [,1] [,2] > [1,] 1 13 > [2.] 2 18 > [3,] 3 14 > [4,] 4 20 > > if(A[,2] > 15) > > B > [,1] [,2] > [1,] 2 18 > [2,] 4 20 > >It's easiest to get help if you give your objects as the output from ?dput. This is just simple indexing: B <- A[A[, 2] > 15, ]
On May 12, 2010, at 3:14 PM, Clark Johnston wrote:> > Is there a way to create a new matrix from and existing matrix with > > A > [,1] [,2] > [1,] 1 13 > [2.] 2 18 > [3,] 3 14 > [4,] 4 20 > > if() > > B > [,1] [,2] > [1,] 2 18 > [2,] 4 20Try (untested absent reproducible example); A[A[,2] > 15, ] This (should) create a logical vector in the first argument to "[" which has the effect of returning the rows for which that vector is TRUE.> > > -- > View this message in context: http://r.789695.n4.nabble.com/manipulating-a-matrix-tp2196610p2196610.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.David Winsemius, MD West Hartford, CT