0

i need to remove a certain part of string if it's a exact match with a couple of keys. For example in my dataframe i have the string "PCPSERGIO AUGUSTO DOS SANTOS" i need to remove the PCP at the start of this but not change remove any "p" from "FATURA - PHENIX".

example:

x <- c("PCPSERGIO AUGUSTO DOS SANTOS","FATURA - PHENIX")
x <- removestr(x,"[PCP]")
x
[1] "SERGIO AUGUSTO DOS SANTOS"  "FATURA - PHENIX"

i have tried using the str_remove function as well as the gsub function.

df <- str_remove_all(df,"[PcP]")

1 Answers1

0

Use the global sub function gsub:

gsub(pattern = "PCP", replacement = "", x = x) 
Arturo Sbr
  • 2,773
  • 1
  • 10
  • 34