R: create categorical variables with case_when || 21

Published: 22 January 2022
on channel: Lab Time with R & Python
391
6

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


On this page of the site you can watch the video online R: create categorical variables with case_when || 21 with a duration of hours minute second in good quality, which was uploaded by the user Lab Time with R & Python 22 January 2022, share the link with friends and acquaintances, this video has already been watched 391 times on youtube and it was liked by 6 viewers. Enjoy your viewing!