I have a row of data that is created through ifelse statement of proper data.
mutate(yrsatrisk = ifelse(!is.na(Age_at_death), as.numeric(Age_at_death), ifelse(!is.na(Age_at_last_update), as.numeric(Age_at_last_update), 0))
However one of the datapoints age_at_last_update = 8 but is then recognized as 80. If i sort the output, that row is set at 80, everything else recognizes it as 80 but one with if else statement that does yrsatrisk - 74 which gives an output of -66
1060 Male 79 15 15 15 15 15 5 30 30 20
527 979 Female 79 15 15 15 15 15 5 30 30 20
26 828 Male 8 15 15 15 15 15 -66 30 30 -51
150 101 Female 80 15 15 15 15 15 6 30 30 21
which is created by
"0-14atrisk" = ifelse(yrsatrisk > 14, 15, yrsatrisk),
"15-29atrisk" = ifelse(yrsatrisk > 29, 15, ifelse(yrsatrisk > 14 & yrsatrisk < 30, (as.numeric(yrsatrisk) - 14), 0)),
"30-44atrisk" = ifelse(yrsatrisk > 44, 15, ifelse(yrsatrisk > 29 & yrsatrisk < 45, (as.numeric(yrsatrisk) - 29), 0)),
"45-59atrisk" = ifelse(yrsatrisk > 59, 15, ifelse(yrsatrisk > 44 & yrsatrisk < 60, (as.numeric(yrsatrisk) - 44), 0)),
"60-74atrisk" = ifelse(yrsatrisk > 74, 15, ifelse(yrsatrisk > 59 & yrsatrisk < 75, (as.numeric(yrsatrisk) - 59), 0)),
"75-85+atrisk" = ifelse(yrsatrisk > 74, (as.numeric(yrsatrisk) - 74) , 0),
"0-29atrisk" = ifelse(yrsatrisk > 29, 30, yrsatrisk),
"30-59atrisk" = ifelse(yrsatrisk > 59, 30, ifelse(yrsatrisk > 29 & yrsatrisk < 60, yrsatrisk, 0)),
"60-85+atrisk" = ifelse(yrsatrisk > 59, (as.numeric(yrsatrisk) - 59), 0))
This is not fixed by forcing yrsatrisk with as.numeric prior to the mutate either. It currently means I have to output the data and edit it and re-input for it to work.
Any ideas?
Aucun commentaire:
Enregistrer un commentaire