In this tutorial, we will learn how to find string length in R programming.

To find the length of a String in R, use nchar() function. Following is the syntax of nchar function.

where x is of character data type

String Length in R

Example to find length of String in R

In this example, we will initialize a variable with a String value and find its length using nchar(string) function.

Example to find length of a number in R

nchar automatically type casts number to character

You may try nchar(c) function for other data types to find the length.

Conclusion

In this R Tutorial, we have learned to use nchar(x) to find the string length or number length in R programming language.