I need help with finding a pattern and replacing it by two different ways. For example, the word "Code/i" should be replaced with "Code, Codi".
What code should I use in replacement to get two results separated by comma? I am new to R and assuming some metacharacters or regex needs to be used? Also, i need to use base functions and no external packages. Appreciate any feedback and help as im stuck! Thanks
a <- c("Code/i", "Karina")
gsub(pattern = "/i", replacement= "", a)
Desired outcome:
"Code, Codi, Karina"
You can use
subandpaste0and subset your vectoraon the relevant values (those that contain the pattern/):Data:
Solution:
Result: