Page 206 - Data Science class 11
P. 206
You will observe that the character A has got a hex value of 41, a blank space null or o, small t 74 and small n 6E.
Through the following example, you will see what raw vector is.
Example
Enter the following code snippet in the script panel:
x <- "A test string"
(y <- charToRaw(x))
is.vector(y) # TRUE
rawToChar(y)
is.raw(x)
is.raw(y)
Run to see the following in the console panel:
The raw vector of the string "A test string" has been stored as a stream of hex bytes 41 20 74 65 73 74 20 73 74 72 69
6e 67 in memory. Here, the charToRaw function has been used to display the string in Hex and vice versa, the function
rawToChar has been used to bring back the string from computer storage.
Similarly, the string "Hello" shall be stored as hex 48 65 6c 6c 6f.
• Numeric object: How old are you?
my_age <- 78
• Character object: What’s your name?
my_name <- "VK Jain"
• Logical object: Are you a data scientist?
# (yes/no) <=> (TRUE/FALSE)
is_datascientist <- TRUE
Note that, character vectors can be created using double (") or single (’) quotes. If your text contains quotes, you
should use escape sequence"\" as follows:
‘My friend\’s name is "Sapna"’
• [1] "My friend’s name is \"Sapna\""
# or use this
"My friend’s name is \"Sapna\""
• "My friend’s name is \"Sapna\""
It is possible to use the function class() to see what type a variable is:
class(my_age)
204 Touchpad Data Science-XI

