Re: [R] question about matrix one column values matching a vector ofvalues

From: <Bill.Venables_at_csiro.au>
Date: Mon, 10 Mar 2008 10:53:56 +1000

> 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:Bill.Venables_at_csiro.au
http://www.cmis.csiro.au/bill.venables/

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Waverley
Sent: Monday, 10 March 2008 9:23 AM
To: r-help; r-help_at_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_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.

______________________________________________
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.
Received on Mon 10 Mar 2008 - 00:58:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 10 Mar 2008 - 01:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive