Extract or replace substrings in a character vector.
1 2 3 4
a character vector.
integer. The first element to be replaced.
integer. The last element to be replaced.
a character vector, recycled if necessary.
substring is compatible with S, with
last instead of
For vector arguments, it expands the arguments cyclically to the
length of the longest provided none are of zero length.
When extracting, if
start is larger than the string length then
"" is returned.
For the extraction functions,
text will be
converted to a character vector by
as.character if it is not
For the replacement functions, if
start is larger than the
string length then no replacement is done. If the portion to be
replaced is longer than the replacement string, then only the
portion the length of the string is replaced.
If any argument is an
NA element, the corresponding element of
the answer is
Elements of the result will be have the encoding declared as that of
the current locale (see
Encoding) if the corresponding
input had a declared Latin-1 or UTF-8 encoding and the current locale
is either Latin-1 or UTF-8.
If an input element has declared
"bytes" encoding (see
Encoding, the subsetting is done in units of bytes not
substr, a character vector of the same length and with the
same attributes as
x (after possible coercion).
substring, a character vector of length the longest of the
arguments. This will have names taken from
x (if it has any
after coercion, repeated as needed), and other attributes copied from
x if it is the longest of the arguments).
x with a declared encoding (see
Encoding) will be returned with the same encoding.
The S4 version of
last; this version
These functions are often used with
nchar to truncate a
display. That does not really work (you want to limit the width, not
the number of characters, so it would be better to use
strtrim), but at least make sure you use the default
nchar(type = "c").
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
The New S Language.
Wadsworth & Brooks/Cole. (
1 2 3 4 5 6 7 8 9 10 11
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.