Last active
January 26, 2017 07:34
-
-
Save Keiku/a9400d072a5d74d19000e0ab6845e43b to your computer and use it in GitHub Desktop.
impute a included NA valiable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
data <- data_frame(var = c(0, NA, 2)) | |
data %>% mutate(var = coalesce(var, 1)) | |
data %>% mutate(var = replace(var, which(is.na(var)), 1)) | |
data %>% mutate(var = if_else(is.na(var), 1, var)) | |
# A tibble: 3 × 1 | |
# var | |
# <dbl> | |
# 1 0 | |
# 2 1 | |
# 3 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment