I've got to create a cohort analysis table that looks something like this: Final Form
And, I've got data of the following form:
Each row represents a unique ID. I'm having trouble writing code that will map the changes of the numbers from 0 to 1 or 2 and then back to 0 in the same particular row. The month columns in the final table should contain the sum total all the slides of all particular rows/IDs from one month to another. These slides can be from 0 to 1 or 2 and then back in subsequent months. All the NAs in the data are to be ignored. Only data post NAs are to be taken, as that is when the new user has come in. I already have calculated the values for all total new users, but am unable to get the total slides per month from 0 to 1 or 2 and back to 1 or 0 for each month.
Final Form table is how the data should look. For example in column M2, 7 rows have slipped to the value 1 in the row M1. The row M1 shows cumulative changes i.e. if there's a change in any of the 1156 values from 0 to 1 or 2 and then back again to 1 or 0, then the change needs to reflect in the column values of the same row. For example, M3 column in row M1 shows that there are 2 values that have turned to either values 1 or 2.(This could be from the same ID's reflected in column M2, or entirely new ones. Of the 7 earlier, 5 values could have gone back to 0, with no new ids changing value from 0.)