0

I'm trying to run a filter but it's failing due to the '/' symbol that's not recognised. I would like to rename the text in R by removing the' /'. I know I can rename it in excel before picking up file but I would rather learn how to rename it in R.

This is the command:

Pfizervaccine <- Covidvaccine %>% filter(grepl('PFIZER\BIONTECH', VAX_MANU))

I've tried the command for other vaccines and it works fine, so I know it's to do with the '/' symbol. e.g. Janssenvaccine <- Covidvaccine %>% filter(grepl('JANSSEN', VAX_MANU))

I've attached a screenshot showing the structure of the data.

  • Backslashes are special characters in regex. With `grepl` you can set the argument `fixed = TRUE` which will treat the special characters as regular characters, making your code `Covidvaccine %>% filter(grepl('PFIZER\BIONTECH', VAX_MANU, fixed = TRUE))`. (Generally `fixed = TRUE` is a good idea unless you need to use the special pattern matching of regex -- it will be more efficient if it knows it's just doing an exact match) – Gregor Thomas Jan 04 '23 at 01:21

0 Answers0