R: Convert Strings to Integers (original) (raw)
strtoi {base} | R Documentation |
---|
Description
Convert strings to integers according to the given base using the C function strtol
, or choose a suitable base following the C rules.
Usage
strtoi(x, base = 0L)
Arguments
x | a character vector, or something coercible to this byas.character. |
---|---|
base | an integer which is between 2 and 36 inclusive, or zero (default). |
Details
Conversion is based on the C library function strtol
.
For the default base = 0L
, the base chosen from the string representation of that element of x
, so different elements can have different bases (see the first example). The standard C rules for choosing the base are that octal constants (prefix 0
not followed by x
or X
) and hexadecimal constants (prefix0x
or 0X
) are interpreted as base 8
and16
; all other strings are interpreted as base 10
.
For a base greater than 10
, letters a
to z
(orA
to Z
) are used to represent 10
to 35
.
Value
An integer vector of the same length as x
. Values which cannot be interpreted as integers or would overflow are returned as[NA_integer_](../../base/help/NA%5Finteger%5F.html)
.
See Also
For decimal strings [as.integer](../../base/help/as.integer.html)
is equally useful.
Examples
strtoi(c("0xff", "077", "123"))
strtoi(c("ffff", "FFFF"), 16L)
strtoi(c("177", "377"), 8L)
[Package _base_ version 4.6.0 Index]