I have an R string column containing education information (university + degree). I would like to extract the degree and creating two categorial variables to indicate undergraduate or graduate degree (undergrad.dummy and grad.dummy).
df = data.frame(educ = c("Angelo State University (BBA, Finance; BBA, Economics;)", "University of Oxford (MA, Philosophy; MA, Economics;", "Ross School of Business, University of Michigan (MBA; BBA;)"))
My approach is to create a list of undergrad and graduate degree, like below
undergrad.list = c("BBA", "BA")
grad.list = c("MA", "MBA", "PhD")
What I attempted is to first extract the degree from educ
df$degree = str_match_all(df$educ, "BBA|MS|MBA|BA")
The problem is the result can be a vector, and I'm having difficult time to extract undergrad and grad degree from that for my large dataset. In the end, I'd like to have
df = data.frame(educ = c("Angelo State University (BBA, Finance; BBA, Economics;)", "University of Oxford (MA, Philosophy; MA, Economics;", "Ross School of Business, University of Michigan (MBA; BBA;)"), undergrad.dummy = c(1,0,1), grad.dummy = c(0,1,1))
Hope to get some suggestions to deal with this problem.