You have tried writing: Show
I'll start by just explaining why this didn't work!
The correct syntax looks like this:
I have a dataset with lots of numerical variables, and a character variables that says whether or not low values are suppressed for that observation. In observations where values aren't suppressed, I want to replace NAs 0s (just for specific variables), and I can't figure it out. This is my data:
What I want to do is change NA to 0 in Var 1, if Suppressed=none. I tried
and got
Is there something wrong with my if else statement, or is there another way to do this? Here's the structure of my data:
How do I replace specific values with NA in R?Using R replace() function to update 0 with NA
R has a built-in function called replace() that replaces values in a vector with another value, for example, zeros with NAs.
How do I replace specific values in R?To replace a column value in R use square bracket notation df[] , By using this you can update values on a single column or on all columns. To refer to a single column use df$column_name .
How do you replace values in a vector with Na?If na is a named vector and as. tag = FALSE , the names indicate variable names, and the associated values indicate those values that should be replaced by NA in the related variable. For instance, set_na(x, na = c(v1 = 4, v2 = 3)) would replace all 4 in v1 with NA and all 3 in v2 with NA .
How do I replace missing values in NA with R?How to Replace Missing Values(NA) in R: na.. mutate(). Exclude Missing Values (NA). Impute Missing Values (NA) with the Mean and Median.. |