Description Usage Arguments Examples
Renames the values on a data.frame according to a pattern-value map. An index can be supplied to only operate on a selection of rows. An alternative loopup can be used which allows conditional replacement (e. g., to only change Mazda's in the mtcars dataset).
1 2 3 |
.DF |
A dataframe. |
.index |
An optional index vector of the same length as .DF. |
.replace |
A list of variables changes are applied to. |
.lookup |
An optional variable that can be used as alternative lookup. |
.name_vec |
A vector that serves as a lookup map. This vector is of the form regexp = "replacement". |
.all_variables |
logic, if true, then all varibles will be selected. otherwise, only .replace will be selected |
... |
arguments passed on to other methods |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | model <- rownames(mtcars)
new= rep("Merc 1", dim(mtcars)[1])
mcars <- cbind(mtcars,
model,
new,
stringsAsFactors=FALSE)
make <- c("(?i)^merc"="BMW")
find_replace(mcars,
.replace="model",
.name_vec=make)
find_replace(mcars,
.replace=c("mpg" ,"model", "new"),
.name_vec=make,
.all_variables=FALSE)
find_replace(mcars,
.name_vec=make,
.all_variables = TRUE)
index <- with(mcars, model=="Fiat 128")
find_replace(mcars,
.name_vec=make,
.all_variables=TRUE,
.index=index)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.