To remove a specific character from a string in R, you can use the `gsub` function.
In this example,
str
with a value of "Hello World"
.gsub
function to replace all occurrences of 'l' with an empty string in str
.gsub
function returns a new string with the specified characters replaced.str
.str <- "Hello World"
modified_str <- gsub('l', '', str)
print(paste("Modified string:", modified_str))
Modified string: Heo Word
In this example,
str
with a value of "apple"
.gsub
function to replace all occurrences of 'a' with an empty string in str
.gsub
function returns a new string with the specified characters replaced.str
.str <- "apple"
modified_str <- gsub('a', '', str)
print(paste("Modified string:", modified_str))
Modified string: pple
In this tutorial, we learned How to Remove specific Character from a String in R language with well detailed examples.