R编程如何中将字符串转换为整数(–strtoi()函数)

strtoi()发挥作用:R语言用于将指定的字符串转换为整数。

语法:strtoi(x, base = 0L)参数:x:字符向量base:2到36之间的整数(含2和36), 默认为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 )

【R编程如何中将字符串转换为整数(–strtoi()函数)】输出如下:
[1] 25519 567 [1] 65535 65535 [1] 16693

    推荐阅读