![]() |
VOOZH | about |
In this article we will discuss how to use is.na in R programming language.
is.na is used to check NA values present in the given data and return TRUE if the value is NA, otherwise FALSE
Syntax:
is.na(data)
where, data is a vector/dataframe
is.na() can be used with other methods to add more meaning to the requirement. To count the total NA values present in the data we have to use the sum() function
Syntax:
sum(is.na(data))
To get the positions where NA values are there, by using which() function
Syntax:
which(is.na(data))
A vector is a data structure that can store elements of multiple data types.
Example: R program to get and count NA values in a vector
Output:
[1] 1 2 3 NA 45 34 NA NA 23
[1] FALSE FALSE FALSE TRUE FALSE FALSE TRUE TRUE FALSE
[1] 3
[1] 4 7 8
A dataframe is a data structure that can stores elements of multiple data type in rows and columns
Example: R program to count NA and get NA values in a dataframe
Output:
👁 ImageWe can use sapply() function to get total NA values in the dataframe.
Syntax:
sapply(dataframe, function(variable) sum(is.na(variable)))
where
Example: Use of is.na on a dataframe
Output:
👁 Image