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 " |
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 # [1] "XXXXXXXXXXX" |
gsub(" ", "", my_string) # Using gsub() function in R # [1] "XXXXXXXXXXX"
Related Articles & Further Resources
Have a look at the following R tutorials. They explain topics such as character strings, data conversion, and extracting data.