Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (7.3k points)

How to find the length of a string (number of characters in a string) without splitting it in R? I know how to find the length of a list but not of a string.

And what about Unicode strings? How do I find the length (in bytes) and the number of characters (runes, symbols) in a Unicode string?

1 Answer

0 votes
by

To find the length of a string in R, you can use the nchar() function as follows:

nchar("String")

Output: 

[1] 6

To find the length of multiple strings and exclude NA’s, you can use the stri_length() function from the stringi package as follows:

stri_length(c("String","Count",NA))

Output:

[1]  6  5 NA

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...