![]() |
VOOZH | about |
str_replace() is used to replace the given string with a particular value in R Programming Language. It is available in stringr library, so we have to load this library.
Syntax:
str_replace( "replacing string", "replaced string")
where,
We will use str_replace in dataframe. We can replace particular string in dataframe column by using the following syntax
str_replace(dataframe$column_name, "replacing string", "replaced string")
where,
Example:
Output:
[1] "oops" "python" "php" [1] "HTML5" "css" "jsp"
We can replace the string with "" empty.
Syntax:
str_replace(dataframe$column_name, "replacing string", "")
Example :
Output:
[1] "" "python" "php" [1] "" "css" "jsp"
We can replace multiple string in a particular column by using str_replace_all method.
Syntax:
str_replace_all(dataframe$column_name, c("string1" = "new string",.................,"stringn" = "new string"))
Example:
Output:
[1] "oops" "python" "sql" [1] "R" "css" "servlets"