I want sort the data by ID and Y2 then count the number of rows within
IDs. Assign a "flag" variable to reach row starting from first to
the last row.
For instance, in the following data ID "1" has three rows and each
row is assigned flag sequentially 1, 2,3.
2. In the second step, within each ID, I want get the difference
between the subsequent row values of y1 and y2(date) values.
Within each ID the first value of y1diff and y2diff are always 0. The
second values for each will be the current row minus the previous
lag<-read.table(text=" ID, y1, y2
2, 656, 11/30/2016
output looks like as follows
2, 4, 656 11/30/2016, -94, 305
Rfirstname.lastname@example.org mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.