Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rhilfi
Created April 15, 2021 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhilfi/2f7050c2ef80e50b3522c5be66999da9 to your computer and use it in GitHub Desktop.
Save rhilfi/2f7050c2ef80e50b3522c5be66999da9 to your computer and use it in GitHub Desktop.
replace_empty_string_with_na_r #R
library(summarytools)
library(dplyr)
first_name=c("Hans", "Peter", "", "Fritz", "Susi")
family_name=c("Meier", "Muller", "Zgraggen", "", "Zurcher")
age=c(43,43,23,55,40)
data<-data.frame(first_name, family_name, age)
summarytools::freq(data$first_name)
data<-data %>%
mutate(across(where(is.character),~na_if(.,"")))
data
summarytools::freq(data$first_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment