[R] Computing row differences in new columns

From: Roberto Lodeiro Muller <roberto.muller_at_doctor.com>
Date: Mon, 21 Mar 2011 15:23:33 -0400

Hi

I have the following columns with dates and results, sorted by subject and date. I'd like to compute the differences in dates and results for each patient, based on the previous row. Obviously the last entry for each subject should be a NA.

 Which would be the best way to accomplished that ?

I guess questions like that have been already answered a thousand times, so I apologize for asking one more time.

Thanks

Roberto

SUBJECT
Date
Result
DateDiff
ResultDiff

10751
22-Jul-03
3.5  

10751
13-Feb-04
1.3

10751
20-Aug-04
1.6

10751
08-Mar-05
1.7

10751
30-Aug-05
1.6

10751
21-Feb-06
1.3

10751
31-Aug-06
1.2

10751
27-Feb-07
1.5

10751
29-Aug-07
1

10752
29-Jul-03
5.9

10752
24-Feb-04
5

10752
25-Aug-04
3.6

10752
11-Mar-05
5.1

10752
18-Sep-05
2.2

10752
23-Feb-06
3.1

10752
24-Aug-06
3.7

10752
27-Feb-07
6

        [[alternative HTML version deleted]]



R-help_at_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. Received on Mon 21 Mar 2011 - 19:26:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 21 Mar 2011 - 20:10:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive