[R] seeking tip to keep first of multiple observations per ID

arun smartpink111 at yahoo.com
Fri Mar 15 20:31:11 CET 2013


Hi,

If you can dput() a small part of your dataset e.g. dput(head(yourdataset),20)), it would be helpful.

Otherwise, 

dat1<- data.frame(ID=rep(1:3,times=c(3,4,2)),col2=rnorm(9))
 aggregate(.~ID,data=dat1,head,1)
#  ID       col2
#1  1 -0.0637622
#2  2  1.1782429
#3  3  0.4670021
A.K.



----- Original Message -----
From: Julie Royster <jsdroyster at bellsouth.net>
To: r-help at r-project.org
Cc: 
Sent: Friday, March 15, 2013 12:06 PM
Subject: [R] seeking tip to keep first of multiple observations per ID

Dear R community,

I am a neophyte and I cannot figure out how to accomplish keeping only the
first record for each ID in a data.frame that has assorted numbers of
records per ID.

I studied and found references to packages plyr and sql for R, and I fear
the documentation for those was over my head and I could not identify what
may be there to reach my goal.

If someone could point me toward a method I will gladly study documentation,
or if there is an example posted someplace I will follow it.

THANKS!
Julie 

    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list