Skip to content

Instantly share code, notes, and snippets.

@doron2402
Created October 17, 2017 21:51
Show Gist options
  • Save doron2402/9808e7d562343c3b33cd7ed71de12f44 to your computer and use it in GitHub Desktop.
Save doron2402/9808e7d562343c3b33cd7ed71de12f44 to your computer and use it in GitHub Desktop.
Preprocessing data with R - filling missing values
# import the dataset
dataset = read.csv('Data.csv')
# missing values
dataset$Age = ifelse(is.na(dataset$Age),
ave(dataset$Age, FUN = function(x) mean(x, na.rm=TRUE)),
dataset$Age)
dataset$Salary = ifelse(is.na(dataset$Salary),
ave(dataset$Salary, FUN = function(x) mean(x, na.rm = TRUE)),
dataset$Salary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment