1

I have two data frames containing the same information. The first contains a unique identifier. I would like to user dplyr::inner_join to match by title.

Unfortunately, one of the data frames contains {"} to signify a quote and the other simply uses a single quote

For example, I would like to match the two titles shown below.

The {"}Level of Readiness{"} for HCV treatment
The 'Level of Readiness' for HCV treatment
A. Suliman
  • 12,923
  • 5
  • 24
  • 37
user25494
  • 1,289
  • 14
  • 27
  • 1
    Can you use `gsub("[^[:alnum:] ]", "", str)` to remove any non alphanumeric character and join after that? – AntoniosK Aug 21 '18 at 21:01

1 Answers1

1

You can turn them into single quotes using gsub, but you need to enclose {"} with single quotes and ' with double quotes. Note that fixed = TRUE treats '{"}' as a literal string instead of a regular expression:

gsub('{"}', "'", 'The {"}Level of Readiness{"} for HCV treatment', fixed = TRUE)
# [1] "The 'Level of Readiness' for HCV treatment"
acylam
  • 18,231
  • 5
  • 36
  • 45
  • When I run the code above in R, I get the error below: Error in gsub("{\"}", "'", "The {\"}Level of Readiness{\"} for HCV treatment") : invalid regular expression '{"}', reason 'Invalid contents of {}' – user25494 Aug 21 '18 at 21:14
  • @user25494 sorry, I missed the `fixed = TRUE` option. It should work now. – acylam Aug 21 '18 at 21:15