Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'data.frame': 41953 obs. of 5 variables:
- $ trust_gov : Factor w/ 6 levels "A lot","Somewhat",..: 1 2 2 2 1 2 4 2 2 2 ...
- $ medwell_accuracy: Factor w/ 7 levels "Very well","Somewhat well",..: 2 4 2 3 4 2 1 1 1 1 ...
- $ medwell_leaders : Factor w/ 7 levels "Very well","Somewhat well",..: 2 3 2 4 4 3 1 2 1 1 ...
- $ medwell_unbiased: Factor w/ 7 levels "Very well","Somewhat well",..: 4 4 2 4 3 2 1 2 1 3 ...
- $ medwell_coverage: Factor w/ 7 levels "Very well","Somewhat well",..: 2 4 1 3 3 2 1 1 2 3 ...
- - attr(*, "variable.labels")= Named chr "ID. Respondent ID" "Survey" "Country" "QSPLIT. Split form A or B" ...
- ..- attr(*, "names")= chr "ID" "survey" "Country" "qsplit" ...
- - attr(*, "codepage")= int 65001
- nm <- grep("medwell_", names(df))
- num <- colSums(apply(df[, nm], 1, `%in%`, c("Very well", "Somewhat well")))
- df$new <- ifelse(num == 3, "SAT", "NON_SAT")
- df %>%
- mutate(
- new = ifelse(
- select(., contains("medwell_")) %>%
- map2_dfr(list(c("Very well", "Somewhat well")), `%in%`) %>%
- rowSums() == 3, "SAT", "NON_SAT"
- )
- )
Add Comment
Please, Sign In to add comment