In this video we use the case_when function from the dplyr package to generate categorical variables.
The dataset for the example:
(note that I replaced the assignment operator with = because YouTube does not allow to use angle brackets in the description)
build dataset ----
id = paste0("p", rep(1:4, 7))
id
year = rep(2010:2016, each = 4)
year
note the difference with
rep(2010:2016, 4)
status = c(0, 0, 1, 0, # 0 = not married
0, 1, 1, 0, # 1 = married
0, 1, 1, 0,
1, 1, 1, 0,
1, 1, 0, 0,
1, 1, 0, 0,
0, 1, 1, 0)
df = data.frame(year, id, status)
df
Sur cette page du site, vous pouvez voir la vidéo en ligne R: create categorical variables with case_when || 21 durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Lab Time with R & Python 22 janvier 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 391 fois et il a aimé 6 téléspectateurs. Bon visionnage!