[ top | up ]

Extract Substrings from a Character Vector

Syntax

substr(x, start, stop)
substring(text, first, last = 1000000)

Description

substr takes a character vector as an argument and returns a vector whose elements contain the substring starting with the character at position start up to the character at position stop. If start is larger than the string length then NA is returned. If stop is longer than start and error is signalled.

substring is compatible with S. For vector arguments, it expands the arguments cyclically.

See Also

paste, nchar, strsplit

Examples

x <- c("asfef","qwerty","yuiop[","b","stuff.blah.yech") substr(x,3,5) substring(x,3,5) substring(x,3,3:5)