我的两个数据框具有相同的字符列。使用 dplyr::full_joint 在此列中加入它们会很容易。但问题是common 列在拼写上有细微但明显的差异。相对于定义技能的每个字符串,拼写差异很小:
Skill Grade_Judge_A
pack & ship 1
pack & store 5
sell 3
Design a room 9
Skill Grade_Judge_B
pack and store 3
pack & ship 7
sell 2
Design room 6
如何在下面实现所需的输出:
Skill Grade_Judge_A Grade_Judge_B
pack & ship 1 3
pack & store 5 7
sell 3 2
Design a room 9 6
我正在考虑根据“技能”列中字符串之间的距离匹配两个数据框中的行,例如使用 stringdist 包。如果两根弦之间的差异很小,则意味着技能相同。
我更喜欢 dplyr/tidyverse 解决方案。
这是数据帧 A 的实际输入:
> dput(df_A)
structure(list(skill = c(" [Assess abdomen for a floating mass]",
" [Assess Nerve Root Compression]", " [Evaluate breathing effort (rate, patterns, chest expansions)]",
" [Evaluate Plantar Reflex/Babinski sign]", " [Evaluate Speech]",
" [External palpation of a uterus]", " [Heel to Shin test]",
" [Inspect anterior chamber of eye with ophthalmoscope or penlight]",
" [Inspect breast]", " [Inspect Overall Skin Color/Tone]", " [Inspect Skin Lesions]",
" [Inspect Wounds]", " [Mental Status/level of consciousness]",
" [Nose/index finger]", " [Percuss abdomen to determine spleen size]",
" [Percuss costovertebral angle for kidney tenderness]", " [Percuss for diaphragmatic excursion]",
" [Percuss the abdomen for abdominal tones]", " [Percuss the abdomen to determine liver span]"
), `2016-09-17 13:41:08` = c(1, 1, 5, 3, 4, 0, 4, 3, 3, 5, 4,
5, 5, 3, 1, 1, 2, 4, 1)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -19L), .Names = c("skill", "2016-09-17 13:41:08"
))
和数据框B:
> dput(df_B)
structure(list(skill = c(" [Assess abdomen for floating mass]",
" [Assess nerve root compression]", " [Evaluate breathing effort (rate, patterns, chest expansion)]",
" [Evaluate plantar reflex/Babinski sign]", " [Evaluate speech]",
" [External palpation of uterus]", " [Heel to shin test]", " [Inspect anterior chamber of the eye with opthalmoscope or penlight]",
" [Inspect breasts]", " [Inspect overall skin color/tone]", " [Inspect skin lesions]",
" [Inspect wounds]", " [Mental status/level of consciousness]",
" [Nose/Index finger]", " [Percuss costovertebral angle for kidney tenderness]",
" [Percuss for diaphragmatic excursion]", " [Percuss the abdomen for abdominal tones]",
" [Percuss the abdomen to determine liver span]", " [Percuss the abdomen to determine spleen size]"
), `2016-09-21 07:58:43` = c(0, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -19L), .Names = c("skill", "2016-09-21 07:58:43"
))
这是两个数据框的头:
> head(df_A)
# A tibble: 6 × 2
skill `2016-09-17 13:41:08`
<chr> <dbl>
1 [Assess abdomen for a floating mass] 1
2 [Assess Nerve Root Compression] 1
3 [Evaluate breathing effort (rate, patterns, chest expansions)] 5
4 [Evaluate Plantar Reflex/Babinski sign] 3
5 [Evaluate Speech] 4
6 [External palpation of a uterus] 0
第二个:
> head(df_B)
# A tibble: 6 × 2
skill `2016-09-21 07:58:43`
<chr> <dbl>
1 [Assess abdomen for floating mass] 0
2 [Assess nerve root compression] 2
3 [Evaluate breathing effort (rate, patterns, chest expansion)] 2
4 [Evaluate plantar reflex/Babinski sign] 2
5 [Evaluate speech] 2
6 [External palpation of uterus] 1