Convert Numbers with Comma Separator to Numeric in R (Example Code)

In this R tutorial you’ll learn how to change thousand separators from comma to point.

Example Data

x <- "11,222"                            # Constructing example data object
x                                        # Printing example data object
# [1] "11,222"

Example: Adjusting Data Object with Comma as Thousand Separator

x_new <- as.numeric(gsub(",", "", x))    # Modifying example data object
x_new                                    # Printing new data object
# [1] 11222

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