在 R 编程中将字符串转换为整数 - strtoi()函数
R 语言中的strtoi()
函数用于将指定的字符串转换为整数。
Syntax: strtoi(x, base=0L)
Parameters:
x: character vector
base: integer between 2 and 36 inclusive, default is 0
示例 1:
# R program to illustrate
# strtoi function
# Initializing some string vector
x <- c("A", "B", "C")
y <- c("1", "2", "3")
# Calling strtoi() function
strtoi(x, 16L)
strtoi(y)
输出 :
[1] 10 11 12
[1] 1 2 3
示例 2:
# R program to illustrate
# strtoi function
# Calling strtoi() function over
# some specified strings
strtoi(c("0xff", "023", "567"))
strtoi(c("ffff", "FFFF"), 16L)
strtoi(c("246", "135"), 8L)
输出:
[1] 255 19 567
[1] 65535 65535
[1] 166 93