[R] Which function to use: grep, replace, substr etc.?
syrvn
mentor_ at gmx.net
Sun Oct 16 18:58:46 CEST 2011
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.
More information about the R-help
mailing list