How to Get the Length of a Character String in R (Example Code)

This tutorial explains how to find the amount of characters in a string in R.

Construction of Example Data

x <- "slfghdslkgnjkdsngjdf"        # Create a random character string

Example: Apply nchar Function to Get Number of Characters in String

nchar(x)                           # Return length of string
# 20

Related Articles

Please have a look at the following R programming tutorials. They focus on similar topics as this page:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed