这是我的dataframe:
或者你可以复制它:
structure(list(A_levels = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
College_Uni = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), CSEs = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0), NVQ_HND_HNC = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0), O_levels_GCSEs = c(1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1), Other_prof_qual = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0), Prefer_not_to_answer = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0), None_of_the_above = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0), id = 5000:5010), row.names = c(NA, -11L), class = c("tbl_df",
"tbl", "data. Frame")) -> df
我想改变一个新变量的edu_level,它的值如下:
#my vairabe edu_level
#College_Uni high
#A_levels medium
#O_levels_GCSEs medium
#CSEs) low
#NVQ_HND_HNC low
#Other_prof_qual low
#Prefer_not_to_answer NA
#None_of_the_above NA
我想可能是因为是选择题,有些人有两个以上的水平,所以我不知道如何指定分类。
我想首先选择其edu_level的优先级为最高学位。例如,如果它同时具有College_Uni和A_levels,则edu_level的值为高。
3条答案
按热度按时间whlutmcx1#
我创建了一个不同教育水平的数据框来展示解决方案;
数据:
6g8kf2rb2#
试试这个,让我知道它是否有帮助。我将您的调查从0和1转换为排名数字,然后从每行中找到最大数字。
可重现数据
工作
结果(见最右栏)
nxagd54h3#
这里有一个方法