Remove Newline from Character String in R (2 Examples) | Line Break Symbol | cat, gsub & str_replace

preview_player
Показать описание
R code of this video:

my_string <- "aaa\nbbbbb\ncc\nd" # Create example character string
cat(my_string) # Display example character string

my_string_new1 <- gsub("[\r\n]", "", my_string) # Apply gsub() function
my_string_new1 # Print updated character string

library("stringr") # Load stringr package

my_string_new2 <- str_replace_all(my_string, "[\r\n]" , "") # Apply str_replace_all() function
my_string_new2 # Print updated character string

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

Thanks for the video. Could you help me here.
Below is the code (creating data frame and printing ), I wrote and ran in w3schools editor

df <- data.frame(
names=c("a", "b", "c"),
details=c("manager", b="analyst", "developer")

print(str(df))
)

As I am using str in print, am getting NULL in last after running the program

I must have to print and use str to inspect data frame.

How to avoid null here ?

manjunath