terça-feira, 10 de abril de 2018

Treating missing values in R

There are different ways to treat missing values in R. One of the most commom ways to do that, is to replace the NA values with the mean (or mode). You can do that in a vector (or a column/line from  a data frame) using the is.na function:

> testena <- c(2,3,8,NA,9)
> testena[is.na(testena)] <- mean(testena,na.rm=T)
> testena
[1] 2.0 3.0 8.0 5.5 9.0

On RStudio...



Check out my new book about R Language http://www.amazon.com/dp/B00SX6WA06

Nenhum comentário:

Postar um comentário

Leave your comment here!