[R] How to handle Which on two matrices that do not have same number of rows

Henrique Dallazuanna wwwhsd at gmail.com
Wed Feb 13 20:40:20 CET 2008


Try this:

merge(data.frame(P1), data.frame(PC), by.x=1, by.y=1)

On 13/02/2008, My Coyne <mcoyne at boninc.com> wrote:
> R-newbie question
>
>
>
> I have 2 matrices
>
> (a)   P1 has only one column of 32K rows
>
> (b)   PC  has 2 column {P, C} of 3200 rows
>
>
>
> Every values in P1 matches with a value in PC[,p] (column p).  I would like
> to use Which to search for all value in P1 that matchex PC[,p] and get the
> PC[,c].  However because P1 and PC does not have the same number of rows, I
> got lots of 'NA'.  Thanks for your help.
>
>
>
> Example..
>
>
>
> P1 <- {'p001', 'p001', 'p002', 'p010'..}
>
> PC <- { c('p001','class a'), c('p002', 'class b'),.. , c('p010', 'class
> 10')}
>
>
>
> Result <- {c('p001', 'class a'), c('p001', 'class a'), c ('p002', 'class
> b'), c('p010', 'class 10')...}
>
>
>
>
>
> My D. Coyne
>
>
>
>
>
>
>
>
>         [[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.
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list