Created
December 7, 2016 14:45
-
-
Save aammd/74e32f27c62058ba8df4b4b74f01df51 to your computer and use it in GitHub Desktop.
This file contains hidden or 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) | |
library(tidyr) | |
words_some_missing <- data_frame(one_word = c(NA, "M", NA), | |
second_word = c("F", NA, NA)) | |
words_some_missing %>% | |
unite(sex, one_word, second_word) | |
## that sticks the NAs together, which I think is something you dont want? In | |
## that case, just replace the NAs with and empty string before combining them. | |
## Then, combine them with another empty string as replacement: | |
words_some_missing %>% | |
replace_na(list(one_word = "", second_word = "")) %>% | |
unite(sex, one_word, second_word, sep = "") | |
# I'm assuming here that this is what you want -- you have the sex spread across | |
# several columns and you want to bring it into a single column? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment