String operation in R

example draw from “The art of R programming”

grep

grep("Pole", c("Equator", "North Pole", "South Pole", "Sea"))
## [1] 2 3

nchar

nchar("South Pole")
## [1] 10

paste and paste0

paste("north", "Pole")
## [1] "north Pole"
paste0("north", "Pole", sep = " ")
## [1] "northPole "
paste0("north", "Pole")
## [1] "northPole"

more

sprintf, substr, strsplit, regexr, regexr

related package

stringr

stringr is a set of simple wrappers that make R's string functions more consistent, simpler and easier to use. It does this by ensuring that: function and argument names (and positions) are consistent, all functions deal with NA's and zero length character appropriately, and the output data structures from each function matches the input data structures of other functions.