Advertisement
gk231192

Untitled

Jun 7th, 2024
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.36 KB | None | 0 0
  1. # Impute missing values in the Ozone and Solar.R columns
  2. library(dplyr)
  3.  
  4. airquality <- airquality %>%
  5.   mutate(
  6.     Ozone = ifelse(is.na(Ozone), median(Ozone, na.rm = TRUE), Ozone),
  7.     Solar.R = ifelse(is.na(Solar.R), mean(Solar.R, na.rm = TRUE), Solar.R)
  8.   )
  9. # Explanation: Median is less affected by outliers and may be preferable for skewed data like Ozone.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement