Skip to content

Instantly share code, notes, and snippets.

@tengpeng
Created February 7, 2016 06:32
Show Gist options
  • Select an option

  • Save tengpeng/f33619812a3a23727427 to your computer and use it in GitHub Desktop.

Select an option

Save tengpeng/f33619812a3a23727427 to your computer and use it in GitHub Desktop.
impute median
impute.med <- function(x) replace(x, is.na(x), median(x, na.rm = TRUE))
df_all <- sapply(df_all, function(x){
if(is.numeric(x)){
impute.med(x)
} else {
x
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment