Description Usage Arguments Examples
FindReplace
allows you to find and replace multiple character string
patterns in a data frame's column.
1 2 | FindReplace(data, Var, replaceData, from = "from", to = "to",
exact = TRUE, vector = FALSE)
|
data |
data frame with the column you would like to replace string patterns. |
Var |
character string naming the column you would like to replace
string patterns. The column must be of class |
replaceData |
a data frame with at least two columns. One contains the patterns to replace and the other contains their replacement. Note: the pattern and its replacement must be in the same row. |
from |
character string naming the column with the patterns you would like to replace. |
to |
character string naming the column with the the pattern replacements. |
exact |
logical. Indicates whether to only replace exact pattern matches
( |
vector |
logical. If |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # Create original data
ABData <- data.frame(a = c("London, UK", "Oxford, UK", "Berlin, DE",
"Hamburg, DE", "Oslo, NO"),
b = c(8, 0.1, 3, 2, 1))
# Create replacements data frame
Replaces <- data.frame(from = c("UK", "DE"), to = c("England", "Germany"))
# Replace patterns and return full data frame
ABNewDF <- FindReplace(data = ABData, Var = "a", replaceData = Replaces,
from = "from", to = "to", exact = FALSE)
# Replace patterns and return the Var as a vector
ABNewVector <- FindReplace(data = ABData, Var = "a", replaceData = Replaces,
from = "from", to = "to", vector = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.