nchar()
get_help()
docs
The nchar()
function comes with R
and is part of the Base R
{base}
package.
We use this function to determine the how many characters (number of characters) in a string. Unfortunately, it is pronounced “en-char.”
nchar(string to count number of characters in)
# Find the number of characters in a string directly
nchar("word")
## [1] 4
# Find the number of characters in a string with multiple words
nchar("This is a whole sentence.")
## [1] 25
# Find the number of characters in a string that was previously defined as a variable.
<- "heyo!"
my_string nchar(my_string)
## [1] 5