O'Reilly logo

Data Manipulation with R by Jaynal Abedin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Missing values in R

Missing values are part of the data manipulation process and we will encounter some missing values in almost every dataset. So, it is important to know how R handles missing values and how they are represented. In R, a numeric missing value is represented by NA while character missing values are represented by <NA>. To test if there is any missing value present in a dataset (data frame), we can use is.na() for each column or we can use this function in combination with the any() function. The following example shows how we can see if there are any missing values present in a dataset:

missing_dat <- data.frame(v1=c(1,NA,0,1),v2=c("M","F",NA,"M")) missing_dat v1 v2 1 1 M 2 NA F 3 0 <NA> 4 1 M is.na(missing_dat$v1) [1] FALSE ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required