Dataframe中行中的类似字符串值

时间:2018-05-27 23:45:08

标签: r data-cleaning

我在R的数据框中有几行,其中疾病的名称相同,但措辞略有改变(加号更改为>)。

有没有办法快速扫描和合并这些行?

一些例子:

Row 59: 872 - SEPTICEMIA OR SEVERE SEPSIS W/O MV ***96+*** HOURS W/O MCC
Row 60: 872 - SEPTICEMIA OR SEVERE SEPSIS W/O MV ***>96*** HOURS W/O MCC

Row 3: 003 - ECMO OR TRACH W MV ***96+*** HRS OR PDX EXC FACE, MOUTH & NECK W MAJ 
Row 4: 003 - ECMO OR TRACH W MV ***>96 HRS*** OR PDX EXC FACE, MOUTH & NECK W MAJ 

2 个答案:

答案 0 :(得分:0)

如果你知道有多少独特记录,你可以进行文本聚类:

> disease.df
     [,1]                                                            
row1 "SEPTICEMIA OR SEVERE SEPSIS W/O MV 96+ HOURS W/O MCC"          
row2 "SEPTICEMIA OR SEVERE SEPSIS W/O MV >96 HOURS W/O MCC"          
row3 "ECMO OR TRACH W MV 96+ HRS OR PDX EXC FACE, MOUTH & NECK W MAJ"
row4 "ECMO OR TRACH W MV >96 HRS OR PDX EXC FACE, MOUTH & NECK W MAJ"

> d <- adist(disease.df)
> rownames(d) <- disease.df
> hc <- hclust(as.dist(d))
> data.frame(disease.df,cutree(hc,k=2))
                                                     disease.df 
cutree.hc..k...2.
row1           SEPTICEMIA OR SEVERE SEPSIS W/O MV 96+ HOURS W/O MCC                 
1
row2           SEPTICEMIA OR SEVERE SEPSIS W/O MV >96 HOURS W/O MCC                 
1
row3 ECMO OR TRACH W MV 96+ HRS OR PDX EXC FACE, MOUTH & NECK W MAJ                 
2
row4 ECMO OR TRACH W MV >96 HRS OR PDX EXC FACE, MOUTH & NECK W MAJ                 
2

答案 1 :(得分:0)

include 'yith-woocommerce-wishlist/wishlist-view.php';

我使用此代码查找重复值。