Hi Bibek,
how about this?

dta<-read.table(textConnection("ID      Time
1       3
1       6
1       7
1       10
1       16
2       12
2       18
2       19
2       25
2       28
2       30"),header=T)

dta$delta<-with(dta,ave(Time,ID,FUN=function(x)c(0,diff(x))))
dta

hth.

Am 14.12.2012 16:51, schrieb bibek sharma:
> Hello R User,
> In the sample data given below, time is recorded for each id
> subsequently. For the analysis, for each id, I would like to set 1st
> recorded time to zero and thereafter find the difference from previous
> time. I.e. for ID==1, I would like to see Time=0,3,1,3,6. This needs
> to be implemented to big data set.
> Any suggestions are much appreciated!
> Thanks,
> Bibek
> 
> ID    Time
> 1     3
> 1     6
> 1     7
> 1     10
> 1     16
> 2     12
> 2     18
> 2     19
> 2     25
> 2     28
> 2     30
> 
> ______________________________________________
> 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.

Reply via email to