Had the same problem recently. I used a loop. Assume your data frame is called "data" and your units of observation are "Subject".
first.round.index=NULL final.round.index=NULL for(i in unique(Subject)){ first.round.index[i]=min(which(Subject==i)) final.round.index[i]=max(which(Subject==i)) } first.round.index=first.round.index[is.na(first.round.index)==F] final.round.index=final.round.index[is.na(final.round.index)==F] ##This gives you the row numbers for first, respectively last, observation for each subject ##Then you can select the data rows of your data according to first- or final.row.index, e.g.: data.first.round=data[first.round.index, ] data.final.round=data[final.round.index, ] ------------------------- cuncta stricte discussurus ------------------------- -----Ursprüngliche Nachricht----- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Luwis Tapiwa Diya Gesendet: Thursday, August 07, 2008 6:22 AM An: R-help@r-project.org Betreff: [R] Obtaining the first /or last record of a subject in alongitudinal study Dear R users, I was wondering if anyone knows how to obtain(subset) the first and/or the last record of a subject in a longitudinal setup. Normally in SAS one uses first.variable1 and last.variable1. So my question is that is there an R way of doing this. Regards, -- Luwis Diya, Phd student (Biostatistics), Biostatistical Center, School Of Public Health, Catholic University of Leuven, U.Z. St Raphael, Kapucijnenvoer 35, B-3000 Leuven, Belgium, Cell: +32(0)497 22 94 83 Phone:+32(0)16 32 68 86 [Office] Phone:+32(0)16 32 98 76 [Home] Fax: +32(0)16 33 70 15 Email: [EMAIL PROTECTED] http://med.kuleuven.be/biostat/staff/LD.htm [[alternative HTML version deleted]] ______________________________________________ R-help@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. ______________________________________________ R-help@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.