Learn R Programming

gdata (version 2.19.0)

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(x, prefix, trim=FALSE, ignore.case=FALSE)

Value

Boolean vector of the same length as x.

Arguments

x

character vector to test

prefix

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.

Author

Gregory R. Warnes greg@warnes.net

Details

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

See Also

Examples

Run this code
## 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

Run the code above in your browser using DataLab