Delete All Line Breaks from Character String in R (Example Code)

In this post you’ll learn how to delete newlines from a string in the R programming language.

Creation of Example Data

x <- "Hellooo\nWhat's going oooooon\nHeeeeere???"  # Exemplifying character string

Example: Apply gsub() Function to Remove Newlines from Character String

gsub("[rn]", "", x)                              # Deleting line breaks
# [1] "HelloooWhat's going oooooonHeeeeere???"

Further Resources

Below, you can find some additional resources on topics such as loops, character strings, data conversion, and vectors:

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

Menu
Top