Сопоставление двух фреймов данных с некоторыми символами в R - PullRequest
2 голосов
/ 25 февраля 2020

У меня есть следующие фреймы данных

df1 <- data.frame(
    Description=c("How are you- doing?",	"will do it tomorrow otherwise: next week",	"I will work hard to complete it for nextr week1 or  tomorrow",	"I am HAPPY with this situation now","Utilising this approach can helpα'x-ray",	"We need to use interseting <U+0452> books to solve the issue",	"Not sure if we could do it appropriately.",	"The schools and Universities are closed in f -blook for a week", 	"Things are hectic here and we are busy"))

   

<!-- begin snippet: js hide: false console: true babel: false -->

и я хочу получить следующую таблицу:

d <- data.frame(
    Description=c("Utilising this approach can helpa'x-ray",	"How are you- doing",	" We need to use interseting <U+0452> books to solve the issue ",	" will do it tomorrow otherwise: next week ",	" Things are hectic here and we are busy ",	"I will work hard to complete it for nextr week1 or  tomorrow ",	"The schools and Universities are closed in f -blook for a week", 	" I am HAPPY with this situation now "," I will work hard to complete it for nextr week1 or  tomorrow"))
    f2<- read.table(text="B12	B6	B9
No	Yes	Yes
12	6	9
No	No	Yes
No	No	Yes
No	No	Yes
Yes	No	Yes
11	No	Yes
12	11	P
No	No	Yes

", header=TRUE)

df3<-cbind(d,f2)

Как видно из столбца «Описание», есть пробел и двоеточие, и поэтому 1 после недели - это индекс, и я не смог это исправить. Я хочу сопоставить его на основе "Описание". Поэтому я хочу сопоставить df1 с df2, используя Description. Можем ли мы сделать это в R для этого случая?

1 Ответ

1 голос
/ 26 февраля 2020

Мы можем использовать stringdist объединения из пакета fuzzyjoin для сопоставления данных на основе 'Description'. Мы используем na.omit для удаления строк NA из окончательного фрейма данных.

na.omit(fuzzyjoin::stringdist_left_join(df1, df3, by = 'Description'))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...