R - startsWith(): test if string starts with a given pattern

21 Jan 2018

To test if a string starts with a certain pattern, more efficient than using substr() and testing equality:

x1 <- "foobar"
startsWith(x1, "foo")
# [1] TRUE
[ R  function  string  ]