Skip to content
Prev 74830 / 398502 Next

filter data set unique, duplicate..

maybe you could consider something like this:

dat <- data.frame(x = c(1, 2, 2, 3, 3, 4),
                  y1 = c(1, 1, 2, 1, 7, 8),
                  y2 = c(NA, NA, NA, 5, 5, 4),
                  y3 = c(3, 11, NA, 16, 2, 1))
#############
out <- as.data.frame(lapply(dat[-1], function(y, x) tapply(y, x, max, 
na.rm = TRUE), x = dat["x"]))
out[out == -Inf] <- NA
out$x <- unique(dat["x"])
out


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

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


----- Original Message ----- 
From: "Anders Bj??rges??ter" <anders.bjorgesater at bio.uio.no>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, August 03, 2005 10:40 AM
Subject: [R] filter data set unique, duplicate..