As always, first some prep work before we can work on the exercises: Load the packages & the data we need…
library(tidyverse)
library(sjlabelled)
gp_covid <-
read_csv2("./data/ZA5667_v1-1-0.csv") %>%
set_na(na = c(-99, -77, -33, 98))
across() to recode the trust variables hzcy044a:hzcy052a into dichotomized versions. The value 1 should remain, all others should be 0.
mutate() function and then use recode().
dplyr functions, let’s check if the code worked.
glimpse() to print the output or use View() to a data tab in RStudio.
median() function to calculate an aggregated variable of all trust variables per respondent.
c_across() function. Oh, and don’t forget to ungroup your data at the end (of your pipe).