> a <- matrix (1:16, 4, 4) > b <- c (2,3) > > which(a[, 1] %in% b) [1] 2 3 > > a [,1] [,2] [,3] [,4] [1,] 1 5 9 13 [2,] 2 6 10 14 ## <<---- [3,] 3 7 11 15 ## <<---- [4,] 4 8 12 16 >
Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Waverley Sent: Monday, 10 March 2008 9:23 AM To: r-help; r-help@r-project.org Subject: [R] question about matrix one column values matching a vector ofvalues Hi, I have a matrix a = matrix (1:16, 4, 4) b = c (2,3) I want to find out which rows of a, where a[,1] equals any values of b? I know that if b is only one value, e.g, b=2, then what I want is a[a[,1] == 2,] But what about if it is not one value but a vector of values? Thanks much in advance. -- Waverley @ Palo Alto ______________________________________________ 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. ______________________________________________ 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.