R语言 把字符值转换成ASCII值 – charToRaw()函数
R语言中的 charToRaw() 函数用于将给定的字符转换为其相应的ASCII值或 “原始 “对象。
语法: charToRaw(x)
参数:
x: 要转换的给定字符
例1:
# R program to illustrate
# charToRaw function
# Calling charToRaw() function over
# some alphabets
x <- charToRaw("a")
y <- charToRaw("A")
z <- charToRaw("ab")
# Getting the corresponding ASCII value
x
y
z
输出 :
[1] 61
[1] 41
[1] 61 62
例2:
# R program to illustrate
# charToRaw function
# Initializing some strings
a <- "Geeks"
b <- "GFG is a CS Portal"
# Calling charToRaw() function
# over above strings
c <- charToRaw(a)
d <- charToRaw(b)
# Getting the ASCII values of the above
# specified strings
c
d
输出:
[1] 47 65 65 6b 73
[1] 47 46 47 20 69 73 20 61 20 43 53 20 50 6f 72 74 61 6c