count number of characters in r code example
Example 1: count length of string r
> nchar("foo")
[1] 3
> set.seed(10)
> strn <- paste(sample(LETTERS, 10), collapse = "")
> strn
[1] "NHKPBEFTLY"
> nchar(strn)
[1] 10
Example 2: count word in a string r
library(stringr)
str_count(string = "How many words are in this sentence", pattern = '\\w+')