I am trying to do an exact pattern match using the gsub/sub and replace function. I am not getting the desired response. I am trying to remove the .x and .y from the names without affecting other names.
name = c("company", "deriv.x", "isConfirmed.y")
new.name = gsub(".x$|.y$", "", name)
new.name
[1] "compa" "deriv" "isConfirmed"
company has become compa.
I have also tried
remove = c(".x", ".y")
replace(name, name %in% remove, "")
[1] "company" "deriv.x" "isConfirmed.y"
I would like the outcome to be. "company", "deriv", "isConfirmed"
How do I solve this problem?