nchar Function in R (Example)
The R code on this page illustrates how to count the length of a character string with the nchar() function in the R programming language.
Example Data
my_char <- "This is an example string" # Create example string |
my_char <- "This is an example string" # Create example string
Example: Application of nchar Function
nchar(my_char) # Return length of string # 25 |
nchar(my_char) # Return length of string # 25
The RStudio console returns the value 25. This means that our example string consists of 25 characters.
Video Examples
The following video shows further examples for the application of the nchar function in R: