Hi,

thanks for the tip! I do it as follows now but I still have a problem I do
not understand:


abbrvs <- data.frame(c("peter", "name", "male", "female"),
                              c("P", "N", "m", "f"))
                                                
colnames(abbrvs) <- c("pattern", "replacement")
        
str <- "My name is peter and I am male"

for(m in 1:nrow(abbrvs)) {
                str <- sub(abbrvs$pattern[m], abbrvs$replacement[m], str, 
fixed=TRUE)
                print(str)
        }
        

This works perfectly fine as I get: "My N is P and I am m"

However, when I replace male by female then I get the following:  "My N is P
and I am fem"

but I want to have "My N is P and I am f".

Even with the parameter fixed=true I get the same result. Why is that?




--
View this message in context: 
http://r.789695.n4.nabble.com/Which-function-to-use-grep-replace-substr-etc-tp3909871p3909922.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to