R talk on regular expressions (regex)
[This article was first published on Recology, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Regular expressions are a powerful in any language to manipulate, search, etc. data. Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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.
Ed Goodwin, the coordinator of the Houston R Users group, gave a presentation to the group last night on regular expressions in R. It was a great talk, and he is allowing me to post his talk here.
Enjoy! And thanks for sharing Ed!
To leave a comment for the author, please follow the link and comment on their blog: Recology.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.