Skip to content
Prev 165841 / 398502 Next

the first and last observation for each subject

Hello,

First, order your data by ID and time.

The columns you want in your output dataframe are then

unique(ID),

tapply( x, ID, function( z ) z[ 1 ] )

and

tapply( y, ID, function( z ) z[ lenght( z ) ] - z[ 1 ] )

Best regards,

Carlos J. Gil Bellosta
http://www.datanalytics.com
On Fri, 2009-01-02 at 17:20 +0800, gallon li wrote: