mercredi 6 octobre 2021

Group age in years to di or trichotomous data in R [closed]

So I am trying to group my age group from a dataset in R that has the ages listed in years (from 1920-2002) as well as remove "don't know" and "refused" by making them NA's.

What I have tried:

nids_na$w5_nc_dob_y[nids_na$w5_nc_dob_y== "Don't know"] <- NA 
nids_na$w5_nc_dob_y[nids_na$w5_nc_dob_y== "Refused"] <- NA 



nids_na$w5_nc_dob_y <- ifelse(nids_na$w5_nc_dob_y < 1956, 0, 
                         ifelse(nids_na$w5_nc_dob_y < 1956, 1, 2))

nids_na <- within(nids_na, {
  w5_nc_dob_y <- factor(w5_nc_dob_y, labels = c(
    "+ 65 years old ",
    "19-64 years old"
    ))
})

levels(nids_na$w5_nc_dob_y)
summary(nids_na$w5_nc_dob_y)

It would work just fine if it weren't for the year for age 65 adding to "+ 65 years old " or "19-64 years old".

Aucun commentaire:

Enregistrer un commentaire