Apologies if this has been answered elsewhere, I did look, but couldn't find an example I could replicate.
If I had the following data frame called DF where 1-14 are items with a score of 1, 0 or 3
Id Date 1 2 3 4 5 6 7 8 9 10 11 12 13 14
1 01/01/01 1 0 3 3 1 0 1 3 1 0 3 0 1 1
2 01/02/01 0 3 1 1 0 1 1 1 1 3 1 1 1 3
How would I create a column which averages items 1-7 for each ID excluding 3 or 0 scores (so just 1 values), and then another column doing the same for for 8-14?
So I would have this:
Id Date 1 2 3 4 5 6 7 8 9 10 11 12 13 14 av1-7 av8-14
1 01/01/01 1 0 3 3 1 0 1 3 1 0 3 0 1 1 0.428 0.428
2 01/02/01 0 3 1 1 0 1 1 1 1 3 1 1 1 3 0.57 0.71
If anyone can help, it would be most appreciated.