Search code examples
ratoi

Is there a function in R that does what atoi() does in C?


Is there a function in R that does what atoi() does in C?

More precisely that converts a character to an integer.

e.g. A = 65, P = 80 and so on ?


Solution

  • charToRaw will give you the hex value. You can pass that to as.numeric to get the decimal equivalent

    > as.numeric(charToRaw("A"))
    [1] 65
    > as.numeric(charToRaw("P"))
    [1] 80