R Deleting All White Space in Character String (Example Code)

This tutorial shows how to delete white space from a character string in the R programming language.

Creation of Example Data

my_string <- " X XX X   XXXX X XX   "    # Creating example character string
my_string                                # Returning example character string
# [1] " X XX X   XXXX X XX   "

Example: Apply gsub() Function to Delete All White Space from Character String

gsub(" ", "", my_string)                 # Using gsub() function in R

Related Articles & Further Resources

Have a look at the following R tutorials. They explain topics such as character strings, data conversion, and extracting data.

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