I want to recodate my data, function of decisions rules
An example of rules :
Data with more than 3 variables years
First rule :we corrected data if only one error :
y ≤ y+2 and y+1 < y then y+1 = y
After the previous correction, corrected with the second rule :
- More than 2 identical years, keep the most frequent
- Equality of frequencies : keep the higher
Maybe with an example it's little bit more clear :
ID y1 y2 y3 y4 y5
1 6 7 6 8
2 6 7 7 6 8
3 6 7 8 7 8
4 6 7 8 6 7
6 3 4 5 6 3
the corrected data
ID y1 y2 y3 y4 y5
1 6 7 7 8
2 6 7 7 7 8
3 6 7 8 8 8
4 6 7 7 7 7
6 3 4 5 6 3
If you have any idea to corrected variable function of other variable, many thank's
If I have an ID with 8 years of data, line 4 doesn't work. Do you know why ? It's problem with a lot of NA? Before code :
ID y1 y2 y3 y4 y5 y6 y7 y8
1 6 7 6 8 NA NA NA NA
2 6 7 7 6 8 NA NA NA
3 6 7 8 7 8 NA NA NA
4 6 7 8 6 7 NA NA NA
5 3 4 5 6 3 NA NA NA
6 7 7 8 8 7 8 7 8
after code
y1 y2 y3 y4 y5 y6 y7 y8
1 6 7 7 8 NA NA NA NA
2 6 7 7 7 8 NA NA NA
3 6 7 8 8 8 NA NA NA
4 6 7 8 6 7 NA NA NA
5 3 4 5 6 3 NA NA NA
6 7 7 8 8 8 8 8 8
If you have a solution otherwise I will make a select according to the number of non empty fields