[R] help matching rows of a data frame

David Winsemius dwinsemius at comcast.net
Mon Sep 18 17:29:27 CEST 2017


> On Sep 18, 2017, at 5:13 AM, Therneau, Terry M., Ph.D. <therneau at mayo.edu> wrote:
> 
> This question likely has a 1 line answer, I'm just not seeing it.  (2, 3, or 10 lines is fine too.)
> 
> For a vector I can do group  <- match(x, unqiue(x)) to get a vector that labels each element of x.
> What is an equivalent if x is a data frame?
> 

In the past I've use apply with past to generate "group" identifiers:


x<-data.frame("X0"=c("A","B","C","C","D","A"), "X1"=c(1,2,1,1,3,1))

apply(x, 1, paste, collapse=".")
[1] "A.1" "B.2" "C.1" "C.1" "D.3" "A.1"


> The result does not have to be fast: the data set will have < 100 elements.  Since this is inside the survival package, and that package is on  the 'recommended' list, I can't depend on any package outside the recommended list.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law



More information about the R-help mailing list