R talk on regular expressions (regex)

Regular expressions are a powerful in any language to manipulate, search, etc. data. For example: > fruit <- c("apple", "banana", "pear", "pineapple") > fruit [1] "apple" "banana" "pear" "pineapple" > grep("a", fruit) # there is an "a" in each of the words [1] 1 2 3 4 > > strsplit("a string", "s") # strsplit splits the string on the "s" [[1]] [1] "a " "tring" R base has many functions for regular expressions, see slide 9 of Ed’s talk below. The package stringr, created by Hadley Wickham, is a nice alternative that wraps the base regex functions for easier use. I highly recommend stringr. ...

October 6, 2011 · 1 min · Scott Chamberlain