How can I find and replace values between two dataframes in R

jerH

I have a dataframe from tidytext that contains the individual words from some survey free-response comments. It has just shy of 500,000 rows. Being free-response data, it is riddled with typos. Using textclean::replace_misspellings took care of almost 13,000 misspelled words, but there were still ~700 unique misspellings that I manually identified.

I now have a second table with two columns, the first is the misspelling and the second is the correction.

For instance

allComments <- data.frame("Number" = 1:5, "Word" = c("organization","orginization", "oragnization", "help", "hlp"))
misspellings <- data.frame("Wrong" = c("orginization", "oragnization", "hlp"), "Right" = c("organization", "organization", "help"))

How can I replace all the values of allComments$word that match misspellings$wrong with misspellings$right?

I feel like this is probably pretty basic and my R ignorance is showing....

GKi

You can use match to find the index for words from allComments$Word in misspellings$Wrong and then use this index to subset them.

tt <- match(allComments$Word, misspellings$Wrong)
allComments$Word[!is.na(tt)]  <- misspellings$Right[tt[!is.na(tt)]]
allComments
#  Number         Word
#1      1 organization
#2      2 organization
#3      3 organization
#4      4         help
#5      5         help

In case the right word is not already in allComments$Word cast it to a character:

allComments$Word <- as.character(allComments$Word)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How can I find the nth substring in between two substrings in C?

分類Dev

How I can find out difference of days between two dates in Java

分類Dev

how can i find two substrings

分類Dev

How can I return two values in a controller

分類Dev

How to find and Replace String column values of a Data frame in R

分類Dev

How can I find the duplicated elements in a array and replace them?

分類Dev

How can i replace the values in respect with with missing data with Zero?

分類Dev

How can I replace values in a Transition layer? (gdistance)

分類Dev

Find the difference (set difference) between two dataframes in python

分類Dev

How can I add rows for all dates between two columns?

分類Dev

How can I share my clipboard between two X servers?

分類Dev

How can I erase a line between two CGpoint?

分類Dev

How can I organize interaction between two divs?

分類Dev

How can I delete everything between two markers in a file?

分類Dev

How can I differentiate between two systems at startup menu

分類Dev

How can I use two bash commands in -exec of find command?

分類Dev

how can i check two columns while inserting values?

分類Dev

How can I retrieve and compare two values from a file?

分類Dev

How I can concat two values inside a id of a list

分類Dev

How can I get the values in between single or double quotes?

分類Dev

How can I iterate over two dataframes to compare data and do processing?

分類Dev

How to zip multiple columns between two dataframes into a dictionary object?

分類Dev

How to merge two dataframes based on header and columns values?

分類Dev

How to merge two pandas DataFrames on matching values in a column

分類Dev

How can I tell if my vector matches the variable values in r?

分類Dev

How can I confirm individual changes in a project-wide find and replace?

分類Dev

how can i replace time-series dataframe specific values in pandas?

分類Dev

How can I replace each and every word with 3 values from another dataframe

分類Dev

How can I replace the NULL values in dataframe with Average of Forward and backward fill?

Related 関連記事

  1. 1

    How can I find the nth substring in between two substrings in C?

  2. 2

    How I can find out difference of days between two dates in Java

  3. 3

    how can i find two substrings

  4. 4

    How can I return two values in a controller

  5. 5

    How to find and Replace String column values of a Data frame in R

  6. 6

    How can I find the duplicated elements in a array and replace them?

  7. 7

    How can i replace the values in respect with with missing data with Zero?

  8. 8

    How can I replace values in a Transition layer? (gdistance)

  9. 9

    Find the difference (set difference) between two dataframes in python

  10. 10

    How can I add rows for all dates between two columns?

  11. 11

    How can I share my clipboard between two X servers?

  12. 12

    How can I erase a line between two CGpoint?

  13. 13

    How can I organize interaction between two divs?

  14. 14

    How can I delete everything between two markers in a file?

  15. 15

    How can I differentiate between two systems at startup menu

  16. 16

    How can I use two bash commands in -exec of find command?

  17. 17

    how can i check two columns while inserting values?

  18. 18

    How can I retrieve and compare two values from a file?

  19. 19

    How I can concat two values inside a id of a list

  20. 20

    How can I get the values in between single or double quotes?

  21. 21

    How can I iterate over two dataframes to compare data and do processing?

  22. 22

    How to zip multiple columns between two dataframes into a dictionary object?

  23. 23

    How to merge two dataframes based on header and columns values?

  24. 24

    How to merge two pandas DataFrames on matching values in a column

  25. 25

    How can I tell if my vector matches the variable values in r?

  26. 26

    How can I confirm individual changes in a project-wide find and replace?

  27. 27

    how can i replace time-series dataframe specific values in pandas?

  28. 28

    How can I replace each and every word with 3 values from another dataframe

  29. 29

    How can I replace the NULL values in dataframe with Average of Forward and backward fill?

ホットタグ

アーカイブ