У меня есть некоторые лицензионные данные, и я пытаюсь создать столбец в моем фрейме данных, который сообщает мне, является ли указанная лицензия приемлемой, основываясь на программе, в которую кто-то зарегистрирован.
Для этого я создал список, так как некоторые лицензии приемлемы для более чем одной программы. В идеале я думал о том, что я мог бы каким-то образом использовать этот список в качестве ссылки, чтобы увидеть, была ли программа указана под названием лицензии. Я также пробовал case_when, но продолжал получать ошибки. Я также предпочел бы иметь список, который я могу использовать в качестве карты, потому что названия лицензий, вероятно, будут меняться из года в год.
Пример кода
Ниже приведен фрагмент моего фрейма данных:
df1 <- data.frame(Program = c("Elementary Education", "Elementary Education", "Secondary Math", "Secondary Math", "Secondary ELA", "Secondary ELA"), Licensure = c("Content Area - Elementary Education (Grades 1-6)", "Content Area - Secondary Math (Grades 7-12)", "Content Area - Secondary Math (Grades 7-12)", "Mathematics (Grades 7-12) 1706", "Content Area - Secondary ELA (Grades 7-12)", "Content Area - Early Childhood (preK-Grade 3)"))
Вот список, который я создал, который включает все лицензии с допустимыми программами под каждым:
license_index <- list(
"Content Area - Early Childhood (preK-Grade 3)" = "Elementary Education",
"Content Area - Elementary Education (Grades 1-6)" = "Elementary Education",
"Content Area - Middle Grades ELA (Grades 4-9)" = c("Elementary Education", "Secondary ELA"),
"Content Area - Middle Grades Math (Grades 4-9)" = c("Elementary Education", "Secondary Math"),
"Content Area - Middle School Mathematics (Grades 4-8)" = "Elementary Education",
"Content Area - Secondary ELA (Grades 7-12)" = "Secondary ELA",
"Content Area - Secondary Math (Grades 7-12)" = "Secondary Math",
"Content Area - Secondary English (Grades 7-12)" = "Secondary ELA",
"English Language Arts and Reading (Grades 4-8) 864" = "Elementary Education",
"Core Subjects (Grades EC-6) 1770" = "Elementary Education",
"English Language Arts and Reading (Grades 7-12) 1709" = "Secondary ELA",
"Mathematics (Grades 4-8) 866" = "Elementary Education",
"Mathematics (Grades 7-12) 1706" = "Secondary Math"
)
В идеале, в идеале, мне бы хотелось, чтобы лицензия и программа совпадали или нет:
ideal.df <- data.frame(Program = c("Elementary Education", "Elementary Education", "Secondary Math", "Secondary Math", "Secondary ELA", "Secondary ELA"), Licensure = c("Content Area - Elementary Education (Grades 1-6)", "Content Area - Secondary Math (Grades 7-12)", "Content Area - Secondary Math (Grades 7-12)", "Mathematics (Grades 7-12) 1706", "Content Area - Secondary ELA (Grades 7-12)", "Content Area - Early Childhood (preK-Grade 3)"), match = c("Match", "No", "Match", "Match", "Match", "No"))
Я думаю, что мне нужна функция mutate и, возможно, я использую функцию карты purrr, но я не очень знаком с tidyverse и буду очень признателен за помощь! Заранее спасибо!