Hi,
I have the following data:

> data[1:20,c(1,2,20)]
idr  schyear year
1       8    0
1       9    1
1      10   NA
2       4   NA
2       5   -1
2       6    0
2       7    1
2       8    2
2       9    3
2      10    4
2      11   NA
2      12    6
3       4   NA
3       5   -2
3       6   -1
3       7    0
3       8    1
3       9    2
3      10    3
3      11   NA

What I want to do is replace the NAs in the year variable with the
following:

idr  schyear year
1       8    0
1       9    1
1      10   2
2       4   -2
2       5   -1
2       6    0
2       7    1
2       8    2
2       9    3
2      10    4
2      11   5
2      12    6
3       4   -3
3       5   -2
3       6   -1
3       7    0
3       8    1
3       9    2
3      10    3
3      11   4

I have no idea how to do this. What it needs to do is make sure that for
each subject (idr) that it either adds a 1 if it is preceded by a value in
year or subtracts a 1 if it comes before a year value.

Does that make sense? I could do this in Excel but I am at a loss for how
to do this in R. Please reply to me as well as the list if you respond.

Thanks!
Chris

        [[alternative HTML version deleted]]

______________________________________________
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