I am trying to use the replace()
function in dplyr
to clean my data. I want to run it on all the columns except one. If I use a select()
statement before I lose my character identifiers. I am looking for something like this
newdata<-data %>% replace(((.)>1000),0)
But with an exception
newdata<-data %>% replace(((-StoreID)>1000),0)
Since you didn't provide a reproducible example, here's how it would work on the iris
dataset:
iris %>% mutate_each(funs(replace(., . > 5, NA)), -Species)
We use mutate_each()
to replace by NA
the values greater than 5 in all columns except Species
For your example it would be something like:
data %>% mutate_each(funs(replace(., . > 1000, 0)), -StoreID)
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