Dear R-helpers,

I want to count the number of times ATT_1 has changed in a period of 3
months(can be 4months) from the first YEAR_MTH entry for a CASE_ID. So if
for a CASE_ID we have data only for two distinct YEAR_MTH, then all the
entries should be considered, otherwise only the relevant entries will be
considered for calculation.
E.g. if the first YEAR_MTH entry is 201304 then get the number of changes
till 201307(inclusive), similarly if the first YEAR_MTH entry is 201302
then get the number of changes till 201305.

Dataset
CASE_ID YEAR_MTH ATT_1
CB26A    201302         1
CB26A    201302         0
CB26A    201302         0
CB26A    201303         1
CB26A    201303         1
CB26A    201304         0
CB26A    201305         1
CB26A    201305         0
CB26A    201306         1
CB27A    201304         0
CB27A    201304         0
CB27A    201305         1
CB27A    201306         1
CB27A    201306         0
CB27A    201307         0
CB27A    201308         1

The final dataset should look like

ID_CASE    No.of changes
CB26A        5
CB27A        3

where 'No.of changes' refer to the change in 3 months (201302-201305 for
CB26A and 201304-201307 for CB27A).

How can this be done in R?

Regards,
Abhinaba Roy

	[[alternative HTML version deleted]]

