I have a df with some age variable, and I would like to padronize it.
DEATH CITY BIRTH AGE SEX
> 1 5092017 Acre 3031997 20 MASCULINO
> 2 11022017 Acre 9022017 202 MASCULINO
> 3 11022017 Acre 13071933 83 FEMININO
> 4 11022017 Acre 6022002 15 MASCULINO
> 5 11022017 Acre 2061966 50 FEMININO
> 6 11022017 Acre 28121946 70 FEMININO
> 7 10022017 Acre 4121955 61 MASCULINO
> 8 10022017 Acre 3101943 73 FEMININO
> 9 10022017 Acre 6022017 20 MASCULINO
> 10 9022017 Acre 14012017 226 FEMININO
> 11 9022017 Acre 20071931 85 FEMININO
These lines with 3 characthers represents months (3), days (2) and hours (1) of life, and I want to change it values to 0, as they not completed 1 year old.
I tried to use a if conditional, but it doesn't work...
if((nchar(DO_concatenated$IDADE) == 3)&(funcaoidade(DO_concatenated$IDADE) <=3)){
DO_concatenated$IDADE <- 0))
}
"funcaoidade" its a function that i've created to look only the first character of these numbers
funcaoidade = function(x){
substr(x, start = 1, stop = 1)
}
As I'm a begginer at R programming, I beg for your help hahaha What Am I doing wrong? Thanks in advance
Aucun commentaire:
Enregistrer un commentaire