RE: [R] Tagging identical rows of a matrix

About this list Date view Thread view Subject view Author view Attachment view

From: Liaw, Andy (andy_liaw@merck.com)
Date: Sat 15 May 2004 - 04:50:41 EST


Message-id: <3A822319EB35174CA3714066D590DCD504AF7DA3@usrymx25.merck.com>

Here's one possibility:

> index <- as.numeric(factor(apply(mat, 1, paste, collapse=":")))
> index
[1] 1 2 1 1 2 3

There's probably some better way though...

Andy

> From: Scott Waichler
>
> I would like to generate a vector having the same length
> as the number of rows in a matrix. The vector should contain
> an integer indicating the "group" of the row, where identical
> matrix rows are in a group, and a unique row has a unique integer.
> Thus, for
>
> a <- c(1,2)
> b <- c(1,3)
> c <- c(1,2)
> d <- c(1,2)
> e <- c(1,3)
> f <- c(2,1)
> mat <- rbind(a,b,c,d,e,f)
>
> I would like to get the vector c(1,2,1,1,2,3). I know dist() gives
> part of the answer, but I can't figure out how to use it for
> this purpose without doing a lot of looping. I need to apply this
> to matrices up to ~100000 rows.
>
> Thanks,
> Scott Waichler
> Pacific Northwest National Laboratory
> scott.waichler_at_pnl.gov
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:11 EST