Re: [R] How to match some patterns in a matrix

From: ss <affysnp_at_gmail.com>
Date: Fri, 11 Apr 2008 15:37:00 -0400

Dear Bert,

Thanks a lot for help. I tried and got:

> x2[x2[["name"]] %in% y,]
[1] name id
<0 rows> (or 0-length row.names)
>

Any suggestions?

Alex

On Fri, Apr 11, 2008 at 2:49 PM, Bert Gunter <gunter.berton_at_gene.com> wrote:

> 1. Strictly speaking, y is a one-column matrix if it has a non-null dim
> attribute (it also is a vector).
>
> 2. ?match or ?"%in%" tells you what to do.
>
> x2[x2[["name"]] %in% y,]
>
> is what you want.
>
>
>
>
> -----Original Message-----
> From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org]
> On
> Behalf Of ss
> Sent: Friday, April 11, 2008 11:23 AM
> To: r-help_at_r-project.org
> Subject: [R] How to match some patterns in a matrix
>
> Dear all,
>
> I have a data frame called x2, which looks like:
>
> > dim(x2)
> [1] 2237 2
> > x2[1:4,1:2]
> name id
> 1 STye hggd3
> 2 STy2 bffbd2
> 3 qw22e bdbdbbbd7
> 4 deffrdff nnshfd3
>
> and a vector called y, which looks like:
>
> > dim(y)
> [1] 135 1
> > y[1:3,1]
> [1] ABCDE BDH5 DESRP1
>
> y is a subset of x2$name and I want to select the rows in x2 whose 'name'
> match
> y. Is there an easy way to do so?
>
> I tried subset(x2, y) but it did not work.
>
> Thanks much for your advice.
>
> Alex
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
>

        [[alternative HTML version deleted]]



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 Fri 11 Apr 2008 - 19:39:36 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 Fri 11 Apr 2008 - 21:30:35 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