Hi I have a matrix (4 x 950) and I want to remove 3 rows, where the values from the first column are 713, 714 and 715. I can select the rows, one by one, with mat[mat$first==713,] mat[mat$first==714,] ... but I'm unable to (i) select the 3 rows at once, (ii) select the matrix excluding those rows. How can I do it ? Thanks EJ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Jos? Ernesto Jardim <ernesto at ipimar.pt> writes:> Hi > > I have a matrix (4 x 950) and I want to remove 3 rows, where the values > from the first column are 713, 714 and 715. I can select the rows, one > by one, with > > mat[mat$first==713,] > mat[mat$first==714,] > ... > > but I'm unable to (i) select the 3 rows at once, (ii) select the matrix > excluding those rows. > > How can I do it ?Um, if you can do that, then mat is a dataframe, not a matrix! Something like mat[!(mat$first %in% 713:715),] would seem to work. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 21 Aug 2000, Jos? Ernesto Jardim wrote:> but I'm unable to (i) select the 3 rows at once, (ii) select the matrix > excluding those rows. > > How can I do it ?> x <- matrix(1:10,,2) > x[,1] [,2] [1,] 1 6 [2,] 2 7 [3,] 3 8 [4,] 4 9 [5,] 5 10> x[x[,1]%in%c(2,3),][,1] [,2] [1,] 2 7 [2,] 3 8> x[!x[,1]%in%c(2,3),][,1] [,2] [1,] 1 6 [2,] 4 9 [3,] 5 10>??P. ---- P.Malewski, Maschplatz 8, 38114 Braunschweig, Tel.: 0531 500965, At work: (MH-Hannover): 0511 532 3194 / Fax: 0511 532 3190, P.Malewski at tu-bs.de, peter.malewski at gmx.de, malewski.peter at mh-hannover.de. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 21 Aug 2000, [iso-8859-1] José Ernesto Jardim wrote:> Hi > > I have a matrix (4 x 950) and I want to remove 3 rows, where the values > from the first column are 713, 714 and 715. I can select the rows, one > by one, with > > mat[mat$first==713,] > mat[mat$first==714,] > ... > > but I'm unable to (i) select the 3 rows at once, (ii) select the matrix > excluding those rows. >The hard way (if you had non-contiguous rows): using "|" (logical or) mat[mat$first==713 | mat$first==714 | mat$first==715,] OR mat[mat$first>=713 & mat$first<=715,] If you were going to do a lot of this you could define a "between" function between <- function(x,lower,upper) { x>=lower & x<= upper } mat[between(mat$first,713,715),] To get all the other rows use ! (not), for example mat[!between(mat$first,713,715),] see the "Logical Operators" page in the R documentation. Ben Bolker -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Jos? Ernesto Jardim wrote:> Hi > > I have a matrix (4 x 950) and I want to remove 3 rows, where the values > from the first column are 713, 714 and 715. I can select the rows, one > by one, with > > mat[mat$first==713,] > mat[mat$first==714,] > ... > > but I'm unable to (i) select the 3 rows at once, (ii) select the matrix > excluding those rows. > > How can I do it ? > > Thanks > > EJ >The best way I found after these messages and with your help was (i) selecting diferent rows mat[(mat$first==c(###, ###, ...)),] (ii) excluding diferent rows mat[!(mat$first==c(###, ###, ...)),] Because there were so many diferent options I'm posting this as a 'best option' for the problem. Thanks all EJ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._