I used the below code to remove the part "(MV)" from the end of every string in a vector (specifically row number 1 for all columns and skip column 1 as shown in the code), however, it removed every M, V and MV in the vector even if it is at the start of the string.
df[1,(-1)]<-gsub("[(MV)]","",df[1,(-1)])
How to only remove the (MV) part at the end of each string without affecting the rest of the rest?
Here is a reproducible example:
structure(list(X1 = structure(c(NA, 5447), class = "Date"), X2 = c("AVON(MV)",
"28.34"), X3 = c("BA.(MV)", "750.07"), X4 = c("CMRG(MV)", "10.040000000000001"
), X5 = c("COB(MV)", "143.22999999999999")), .Names = c("X1",
"X2", "X3", "X4", "X5"), row.names = c(NA, -2L), class = "data.frame")
fixedargument ingsub, probably with"(MV)"as your pattern. Example:x <- "MV(MV)"; gsub("(MV)", "", x, fixed=TRUE)Please provide a reproducible example so we know exactly what you're doing.