R - check start (startsWith()) and end (endsWith()) of a string

25 Dec 2018

Check if elements start (startsWith) or end (endsWith) with a string:

# Check whether elements start with a string
startsWith(month.name, "J")
# [1]  TRUE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE
# [12] FALSE

# Check whether elements end with a string
endsWith(month.name, "ember")
# [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE
# [12]  TRUE

[ R  function  string  ]