replace_vars | R Documentation |
replace_vars
could replace any value(s) or values
that match specific patterns to another specific value in a data.table.
replace_vars(.data, ..., from = is.na, to)
.data |
A data.table |
... |
Colunms to be replaced. If not specified, use all columns. |
from |
A value, a vector of values or a function returns a logical value.
Defaults to |
to |
A value. |
A data.table.
replace_dt
iris %>% as.data.table() %>%
mutate(Species = as.character(Species))-> new_iris
new_iris %>%
replace_vars(Species, from = "setosa",to = "SS")
new_iris %>%
replace_vars(Species,from = c("setosa","virginica"),to = "sv")
new_iris %>%
replace_vars(Petal.Width, from = .2,to = 2)
new_iris %>%
replace_vars(from = .2,to = NA)
new_iris %>%
replace_vars(is.numeric, from = function(x) x > 3, to = 9999 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.