Maelle Salmon shows off four useful R functions:
Recently I caught myself using
which(grepl(...))
,animals <- c("cat", "bird", "dog", "fish") which(grepl("i", animals)) #> [1] 2 4
when the simpler alternative is
animals <- c("cat", "bird", "dog", "fish") grep("i", animals) #> [1] 2 4
Read on for another example of using grep()
instead of grepl()
, as well as three other functions you might want to keep in mind. H/T R-Bloggers.