Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
r
communitycreator

What is the charToRaw() function in R?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The charToRaw() function in R is used to return a given character’s ASCII value.

charToRaw(x)

Parameter value

The charToRaw() function takes a single and mandatory parameter value x, representing the character that we want to convert to the ASCII value.

Return value

The charToRaw() function returns the ASCII value of the character passed to it.

Code example 1

We will call the charToRaw() function over some letters in the code below:

# creating our character variables
a <- charToRaw("a")
b <- charToRaw("b")
c <- charToRaw("c")
d <- charToRaw("d")
e <- charToRaw("ab")
# Their ASCII values
a
b
c
d
e
Implementing the charToRaw() function

Code explanation

  • Lines 2-6: We call the charToRaw() function over the characters we created.
  • Line 9-13: We print the variables containing the ASCII values that correspond to the characters we passed to the function.

Code example 2

We will create string characters in the code below and determine their respective ASCII values.

# creating our string variables
a <- "R"
b <- "R language is the best!"
# getting their ASCII values
charToRaw(a)
charToRaw(b)
Implementing the charToRaw() function

Code explanation

  • Lines 2-3: We create string variables a and b.
  • Lines 6-7: We call the charToRaw() function over the string variables.

RELATED TAGS

function
r
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring