我有全名数据,我使用 strsplit() 来获取名称的每个元素。
# Dataframe with a `names` column (complete names)
df <- data.frame(
names =
c("Adam, R, Goldberg, MALS, MBA",
"Adam, R, Goldberg, MEd",
"Adam, S, Metsch, MBA",
"Alan, Haas, MSW",
"Alexandra, Dumas, Rhodes, MA",
"Alexandra, Ruttenberg, PhD, MBA"),
stringsAsFactors=FALSE)
# Add a column with the split names (it is actually a list)
df$splitnames <- strsplit(df$names, ', ')
我也有以下学位列表
degrees<-c("EdS","DEd","MEd","JD","MS","MA","PhD","MSPH","MSW","MSSA","MBA",
"MALS","Esq","MSEd","MFA","MPA","EdM","BSEd")
我想得到每个名字和各自学位的交集。
我不确定如何展平名称列表,以便可以使用 intersect 比较两个向量。当我尝试unlist(df$splitname,recursive=F)
时,它分别返回每个元素。任何帮助表示赞赏。