Hi all. I have certain problem with the extraction of data from matrices. I know how extract elements from a matrix, but what I would like to do is to extract a concrete number, not an element. For example if I have this matrix X: [,1] [,2] [,3] [,4] [1,] 3 13 23 33 [2,] 9 19 29 39 [3,] 10 20 30 40 I can do X[-2] or X[2] in order to eliminate the element of the matrix or to extract it, respectively. But, what I need is to extract or to eliminate a value of the matrix. For example the 29. Can I do this? How? Thanks for the help. -- View this message in context: http://www.nabble.com/Extract-from-matrix-tp15502655p15502655.html Sent from the R help mailing list archive at Nabble.com.
On Fri, 2008-02-15 at 08:10 -0800, _Fede_ wrote:> Hi all. > > I have certain problem with the extraction of data from matrices. I know how > extract elements from a matrix, but what I would like to do is to extract a > concrete number, not an element. For example if I have this matrix X: > > [,1] [,2] [,3] [,4] > [1,] 3 13 23 33 > [2,] 9 19 29 39 > [3,] 10 20 30 40 > > I can do X[-2] or X[2] in order to eliminate the element of the matrix or to > extract it, respectively. > > But, what I need is to extract or to eliminate a value of the matrix. For > example the 29. > > Can I do this? How?Is this the sort of thing you want?> mat <- matrix(c(3,9,10,13,19,20,23,29,30,33,39,40), ncol = 4) > mat[,1] [,2] [,3] [,4] [1,] 3 13 23 33 [2,] 9 19 29 39 [3,] 10 20 30 40> which(mat == 29)[1] 8> mat[which(mat == 29)][1] 29> mat[which(mat == 29)] <- NA > mat[,1] [,2] [,3] [,4] [1,] 3 13 23 33 [2,] 9 19 NA 39 [3,] 10 20 30 40 HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Se ha borrado un texto insertado con un juego de caracteres sin especificar... Nombre: no disponible Url: https://stat.ethz.ch/pipermail/r-help/attachments/20080215/36c98a26/attachment.pl
Try also: mat[mat==29] <- NA On 15/02/2008, _Fede_ <r_stat_solutions at hotmail.es> wrote:> > Hi all. > > I have certain problem with the extraction of data from matrices. I know how > extract elements from a matrix, but what I would like to do is to extract a > concrete number, not an element. For example if I have this matrix X: > > [,1] [,2] [,3] [,4] > [1,] 3 13 23 33 > [2,] 9 19 29 39 > [3,] 10 20 30 40 > > I can do X[-2] or X[2] in order to eliminate the element of the matrix or to > extract it, respectively. > > But, what I need is to extract or to eliminate a value of the matrix. For > example the 29. > > Can I do this? How? > > Thanks for the help. > -- > View this message in context: http://www.nabble.com/Extract-from-matrix-tp15502655p15502655.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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
?which Does something like this help? which(aa==29) aa[ -which(aa==29)] --- _Fede_ <r_stat_solutions at hotmail.es> wrote:> > Hi all. > > I have certain problem with the extraction of data > from matrices. I know how > extract elements from a matrix, but what I would > like to do is to extract a > concrete number, not an element. For example if I > have this matrix X: > > [,1] [,2] [,3] [,4] > [1,] 3 13 23 33 > [2,] 9 19 29 39 > [3,] 10 20 30 40 > > I can do X[-2] or X[2] in order to eliminate the > element of the matrix or to > extract it, respectively. > > But, what I need is to extract or to eliminate a > value of the matrix. For > example the 29. > > Can I do this? How? > > Thanks for the help. > -- > View this message in context: >http://www.nabble.com/Extract-from-matrix-tp15502655p15502655.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. >
Thank you all for your help. Fede _Fede_ wrote:> > Hi all. > > I have certain problem with the extraction of data from matrices. I know > how extract elements from a matrix, but what I would like to do is to > extract a concrete number, not an element. For example if I have this > matrix X: > > [,1] [,2] [,3] [,4] > [1,] 3 13 23 33 > [2,] 9 19 29 39 > [3,] 10 20 30 40 > > I can do X[-2] or X[2] in order to eliminate the element of the matrix or > to extract it, respectively. > > But, what I need is to extract or to eliminate a value of the matrix. For > example the 29. > > Can I do this? How? > > Thanks for the help. >-- View this message in context: http://www.nabble.com/Extract-from-matrix-tp15502655p15518599.html Sent from the R help mailing list archive at Nabble.com.