Skip to content

Instantly share code, notes, and snippets.

@conormm
Created September 1, 2017 19:57
Show Gist options
  • Save conormm/2b73afc8e93e40644d78c186fb18a4b6 to your computer and use it in GitHub Desktop.
Save conormm/2b73afc8e93e40644d78c186fb18a4b6 to your computer and use it in GitHub Desktop.
df %>% map_df(~sum(is.na(.))) %>% glimpse()
Observations: 1
Variables: 28
$ color <int> 19
$ director_name <int> 104
$ num_critic_for_reviews <int> 50
$ duration <int> 15
$ director_facebook_likes <int> 104
$ actor_3_facebook_likes <int> 23
$ actor_2_name <int> 13
$ actor_1_facebook_likes <int> 7
$ gross <int> 884
$ genres <int> 0
$ actor_1_name <int> 7
$ movie_title <int> 0
$ num_voted_users <int> 0
$ cast_total_facebook_likes <int> 0
$ actor_3_name <int> 23
$ facenumber_in_poster <int> 13
$ plot_keywords <int> 153
$ movie_imdb_link <int> 0
$ num_user_for_reviews <int> 21
$ language <int> 12
$ country <int> 5
$ content_rating <int> 303
$ budget <int> 496
$ title_year <int> 108
$ actor_2_facebook_likes <int> 13
$ imdb_score <int> 0
$ aspect_ratio <int> 329
$ movie_facebook_likes <int> 0
replace_na_median <- function(x){
x[is.na(x)] <- median(x, na.rm = TRUE)
x
}
num_df <- df %>%
map_if(is_numeric, replace_na_median) %>%
as_data_frame() %>%
select_if(is_numeric)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment