+5 votes
in Programming Languages by (40.5k points)

I am trying length() to find the number of characters in a string, but it does not return the correct value.

What function should I use to find the length of a string in R?

1 Answer

+2 votes
by (354k points)
selected by
 
Best answer

If you want to find the number of characters in a string, you can use the R function nchar().

> a="Hello world!!"
> nchar(a)
[1] 13


...