Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

startsWith

Determine if a character string "starts with" with the specified characters.


Description

Determine if a character string "starts with" with the specified characters.

Usage

startsWith(str, pattern, trim=FALSE, ignore.case=FALSE)

Arguments

str

character vector to test

pattern

characters to check for

trim

Logical flag indicating whether leading whitespace should be removed from str before testing for a match.

ignore.case

Logical flag indicating whether case should be ignored when testing for a match.

Details

This function returns TRUE for each element of the vector str where pattern occurs at the beginning of the string. If trim is TRUE, leading whitespace is removed from the elements of str before the test is performed. If ignore.case is TRUE, character case is ignored.

Value

Boolean vector of the same length as str.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

Examples

## simplest example:
startsWith( 'Testing', 'Test')

## vector examples
s <- c('Testing', ' Testing', 'testing', 'Texting')
names(s) <- s

startsWith(s, 'Test')                   # ' Testing', 'testing', and 'Texting' do not match
startsWith(s, 'Test', trim=TRUE)        # Now ' Testing' matches
startsWith(s, 'Test', ignore.case=TRUE) # Now 'testing' matches

gdata

Various R Programming Tools for Data Manipulation

v2.18.0
GPL-2
Authors
Gregory R. Warnes, Ben Bolker, Gregor Gorjanc, Gabor Grothendieck, Ales Korosec, Thomas Lumley, Don MacQueen, Arni Magnusson, Jim Rogers, and others
Initial release
2017-06-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.