Skip to content
Prev 324697 / 398503 Next

Read 2 rows in 1 dataframe for diff - longitudinal data

On Jun 3, 2013, at 9:51 PM, arun wrote:

            
I'm not sure why the first one retruns integer values from the ave() call but the second version works:
subid year var
1      36 1999   1
1.1    36 1999   1
1.2    36 1999   1
1.3    36 1999   1

ave( df1$var, df1$subid, FUN=function(x) c( FALSE, x[-1] != x[-length(x)]))
 [1] 0 0 1 0 0 0 1 0 1 1

Perhaps one of the single item groups sabotaged my simple function.
subid year var
3     36 2003   3
7     47 2001   3
9     47 2005   1
10    47 2007   3