Skip to content
Back to formatted view

Raw Message

Message-ID: <F23AF878-414E-41B1-8A88-D1CFF688272A@comcast.net>
Date: 2017-09-18T15:29:27Z
From: David Winsemius
Subject: help matching rows of a data frame
In-Reply-To: <9153c6$7v8l5n@ironport10.mayo.edu>

> 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