【发布时间】:2014-04-04 15:47:22
【问题描述】:
我有 2 个数据框。
在df1 中,我有一列国际疾病分类 (ICD) 诊断代码 (df1$PriDiag) 以及其他信息。
#df1
PriDiag = c("A051","A067","A161","A242","A459")
Admissions = c("106","79","67","50","41")
Pts = c("97","27","45","30","20")
df1 = data.frame(PriDiag,Admissions,Pts)
df1
PriDiag Admissions Pts
1 A051 106 97
2 A067 79 27
3 A161 67 45
4 A242 50 30
5 A459 41 20
在另一个数据框 (df2) 中,我有 ICD 子类别的开始 (df2$Start) 和结束 (df2$End) 限制,以及相关描述 (df2$Description)。
#df2
Start = c("A00","A15","A20","A30")
End = c("A09","A19","A28","A49")
Description = c("Intestinal infectious diseases","Tuberculosis","Certain zoonotic bacterial","Other bacterial diseases")
df2 = data.frame(Start,End,Description)
df2
Start End Description
1 A00 A09 Intestinal infectious diseases
2 A15 A19 Tuberculosis
3 A20 A28 Certain zoonotic bacterial diseases
4 A30 A49 Other bacterial diseases
我要做的是为 df1 分配一个新列,其中包含代码 (df1$PriDiag) 的子类别描述 (df2$Description)。如果代码是数字而不是字符,我将能够做到这一点,但我正在努力寻找一个快速的解决方案。有没有在字符之间搜索的方法?
我想要的结果是一个新的数据框,df3,它看起来像这样:
df3
PriDiag Admissions Pts Description
1 A051 106 97 Intestinal infectious diseases
2 A067 79 27 Intestinal infectious diseases
3 A161 67 45 Tuberculosis
4 A242 50 30 Certain zoonotic bacterial diseases
5 A459 41 20 Other bacterial diseases
我该怎么做?
【问题讨论】:
标签: r