【发布时间】:2022-11-16 14:25:03
【问题描述】:
我有一个用数字而不是名称编码的数据库。 例如 低于高中 = 0 高中/GED = 1 一些大学/贸易学校 = 2 学士学位 = 3 研究生院/高级学位 = 4
我正在使用它的 ifelse 函数,但我正在寻找更快的方法,因为它的数据量大且耗时
Mass_Shooter_fullDatabase$Education <- ifelse(Mass_Shooter_fullDatabase$Education==0,"Less than high school",
ifelse(Mass_Shooter_fullDatabase$Education==1,"High school/GED",
ifelse(Mass_Shooter_fullDatabase$Education==2,"Some college/trade school",
ifelse(Mass_Shooter_fullDatabase$Education==3,"Bachelor's degree",
ifelse(Mass_Shooter_fullDatabase$Education==4,"Graduate school/advanced degree",NA)))))
【问题讨论】:
-
factor(Mass_Shooter_fullDatabase$Education, levels = 0:4, labels = c("Less than high school", "High school/GED", ...))
标签: r