IVIM
IVIM

Reputation: 2367

Convert character to integer OR get ASCII code of character in R

In C/C++ we just do nX = cX - " " to obtain integer nX from character cX.

How do we do it in R ?

Upvotes: 1

Views: 1125

Answers (1)

charToRaw returns a vector with the integer code, without taking into account any declared encoding.

See: ??charToRaw for more help and related functions.

Example:

charToRaw("A")
#[1] 41

charToRaw("AB")
# [1] 41 42
is.vector(charToRaw("AB"))
# TRUE

Upvotes: 3

Related Questions