stringr::str_length("abc")[1] 3
The function stringr::str_length() allows you to determine the length of a string. This will give you the number of characters each string has.
First we’ll count the number of characters in one string (a scalar).
Next we can count the number of characters within each string of a vector.
What about counting white spaces such as spaces (" "), tabs (\t), and new spaces (\n)?
View the strings with stringr::str_view().
[1] │ gataac
[2] │ gat aac
[3] │ gat{\t}aac
[4] │ gat
│ aac
Count the characters in the strings.
You’ll notice that these three white spaces count as 1 character.