nchar()
   get_help() docs


Description

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.”

Conceptual Usage

nchar(string to count number of characters in)

Examples

# 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.
my_string <- "heyo!"
nchar(my_string)
## [1] 5