I have a feature in a df with some missing values which are showing as just "".
unique(page_my_df$Type)
[1] "list" "narrative" "how to" "news feature"
[5] "diary" "" "interview"
I want to replace all instances of "" with "unknown".
page_my_df <- page_my_df %>%
mutate(Type = str_replace(.$Type, "", "unknown"),
Voice = str_replace(.$Voice, "", "unknown"))
Error in mutate_impl(.data, dots) : Evaluation error: Not implemented.
Read some documentation here, specifically under pattern:
Match character, word, line and sentence boundaries with boundary(). An empty pattern, "", is equivalent to boundary("character").
So I tried:
page_my_df <- page_my_df %>%
mutate(Type = str_replace(.$Type, boundary(""), "unknown"),
Voice = str_replace(.$Voice, boundary(""), "unknown"))
Which then gave:
Error in mutate_impl(.data, dots) : Evaluation error: 'arg' should be one of “character”, “line_break”, “sentence”, “word”.
How can I replace empty character strings with "unknown" within dplyr::mutate()?
mutate(Type=ifelse(Type=="", NA, Type))
or evenna_if(Type, "")
– dmi3kno