I have a dataframe df:
var1 var2 "test" "testing" "esten" "etsen" "blest" "estten"
Now I want to delete all "t" inside df to get:
var1 var2 "es" "esing" "esen" "esen" "bles" "esen"
How do I do that?
To remove a character in an R data frame column, we can use gsub function which will replace the character with blank. For example, if we have a data frame called df that contains a character column say x which has a character ID in each value then it can be removed by using the command gsub("ID","",as.
Python String | replace() replace() is an inbuilt function in the Python programming language that returns a copy of the string where all occurrences of a substring are replaced with another substring. Parameters : old – old substring you want to replace. new – new substring which would replace the old substring.
Use gsub
dat <- c("test", "testing", "esten", "etsen", "blest", "estten") gsub("t", "", dat) [1] "es" "esing" "esen" "esen" "bles" "esen"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With