length
nchar
It’s important to note that unlike Python, length
will not work for calculating the length of a string. Take the following example:
vector <- "OH YEAH!"
length(vector)
[1] 1
Our string vector
is one object consisting of multiple characters, and since length
returns the number of objects, we will get 1. If we use the nchar
function, we get what we want:
vector <- "OH YEAH!"
nchar(vector)
[1] 8