Skip to content
Prev 145707 / 398500 Next

Aggregate by First case

try this:

dat <- read.table(textConnection(
"Id         Year
123456 2001
123456 2002
123456 2003
655432 2001
655432 2002
655432 2003"), header = TRUE)
closeAllConnections()

dat[!duplicated(dat$Id), ]
# or
dat[tapply(row.names(dat), dat$Id, head, 1), ]


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Jojje Andersson" <dietaamigo at hotmail.com>
To: <r-help at r-project.org>
Sent: Friday, May 30, 2008 9:13 AM
Subject: [R] Aggregate by First case
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm