Extract Letters from Alphanumeric Character String in R (Example Code)

This article explains how to extract only the letters from an alphanumeric character string in the R programming language.

Creating Example Data

x <- "6734fdbhjwiu738"            # Example character string
x
# [1] "6734fdbhjwiu738"

Example: Keep Only Letters of Alphanumeric Character String Using gsub() Function

gsub("[[:digit:]]", "", x)        # Drop numbers
# [1] "fdbhjwiu"

Further Resources

You may find some additional tutorials on topics such as character strings and RStudio in the following list:

Leave a Reply

Your email address will not be published.

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

Menu
Top