Francisco J. Zagmutt wrote:
If you want to obtain a data frame you can use the functions head and
tail like:
dat=data.frame(id=rep(1:5,3),num=rnorm(15), num2=rnorm(15))#Creates data
frame with id
last=do.call("rbind",by(dat,dat$id,tail,1))#Selects the last observation
for each id
first=do.call("rbind",by(dat,dat$id,head,1))#Selects the first
observation for each id
newdat=rbind(first,last)#Joins data
newdat=newdat[order(newdat$id),]#sorts data by id
Notice that rownames will give you the original row location of the
observations selected
I hope this helps
Francisco
. . .
You might also look at section 4.3 of
http://biostat.mc.vanderbilt.edu/twiki/pub/Main/RS/sintro.pdf
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html