I was wondering how to do encoding and decoding in R. In Python, we can use ord ('a') and chr (97) to convert a letter to a number or convert a number to a letter. Do you know any similar functions in R? Thanks!
For example in python
<P → → Ord ("a")97
<P → → Ord ("A")65
<P → → CHR (97)'a'
<P → → CHR (90)'Z'
FYI: ord (c) in Python For a given length string, one returns an integer representing the Unicode code point of the character when the argument is a unicode object or byte value when the argument is an 8-bit string. For example, ord ('a') returns the integer 97, ord (u '\ u2020') returns 8224. This is the inverse of chr () for 8-bit strings and unichr () for unicode objects. If the unicode argument is given and Python was created with Unicode UCS2, then the character codepoint must be in the range [0..65535] inclusive; otherwise, the length of the string is two, and TypeError will be raised.
chr (i) in Python Returns a single character string whose ASCII code is an integer i. For example, chr (97) returns the string 'a'. This is the inverse of ord (). The argument must be in the range [0..255], inclusive; ValueError will be raised if I am out of this range. See also unichr ().
source share