Get Portions of Character Strings

DESCRIPTION:
Returns a vector of character strings which are substrings of the input.

USAGE:
substring(text, first, last=1000000)

REQUIRED ARGUMENTS:
text:
vector of character strings. This is replicated if first or last is longer than text.
first:
vector giving the position within each element of text that is to be the first character in the respective substring. This is replicated to the maximum length of the arguments. Missing values are not accepted.

OPTIONAL ARGUMENTS:
last:
vector giving the position within each element of text that is to be the last character in the respective substring. This is replicated to the length of text, and must be at least as large as first for each element. Missing values are not accepted.

VALUE:
character vector as long as the longest of text, first and last, containing the specified portions of each character string.

DETAILS:
Characters within each string are numbered from 1 to nchar(string). If first is larger than the length of a string, the returned string is ""; last may address beyond the end of the string, but only the characters from first to the end of string are returned.

SEE ALSO:
nchar , paste , abbreviate .

EXAMPLES:
substring(state.name,1,8)  # first 8 chars of state names
substring(state.name[1:10], 1, c(4,4,3,3,2,3,3,2,2,2))

substring("xxxxxxxxxx",1,1:10) # "x" "xx" "xxx" ...

substring("This is a test",6) # start from 6th char