On Mar 16, 2010, at 9:50 AM, arnaud chozo wrote: > Hi all, > > I have a string vector like that: x=c("1\t\t", "2", "3\t\t\t") > I need to remove all the occurrences of "\t", in order to obtain: x = "1" > "2" "3" > > I'm trying to use the function substring2, and it works for each component, > for example: > substring2(x[1], "\t") ="" > gives x = "1" "2" " 3\t\t\t" > > I'd like to apply this function to each component and I tried the following: > > myfun = function(x, i) { > substring2(x[i], "\t") = "" > } > > lapply(x, myfun) > > which gives x="" "" "" > > I know that I'm wrong somewhere using lapply, but I can't fix it. > > Thanks in advance, > Arnaud Chozo
This is a place to use regular expressions with gsub(): x <- c("1\t\t", "2", "3\t\t\t") > gsub("\\t", "", x) [1] "1" "2" "3" See ?regex and ?gsub Note that you have to double the backslashes in the regex. HTH, Marc Schwartz ______________________________________________ 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.