Friday, April 8, 2011

String operations in R

search and replace functions:
replace first occurrence:
- sub(pattern, replacement, x, ignore.case = FALSE)
and replace all occurences:
- gsub(pattern, replacement, x, ignore.case = FALSE)
e.g.
sub("ich", "wir", "ich Ich ICH") --------> "wir Ich ICH"
sub("ich", "wir", "ich Ich ICH", ignore.case=T) --------> "wir Ich ICH"
gsub("ich", "wir", "ich Ich ICH", ignore.case=T)--------> "wir wir wir"



additional:
useful packages:
- gsubfn -> Homepage

No comments :

Post a Comment