in r: How to Use function in R

When working in a real-time dataset, you won’t get clean data. Real-world data is always filled with missing values. So if you are developing an algorithm that can predict the future values, you first need to clean the existing data, and based on that, you can create a model and feed the data.

What is missing values in R

Missing values in R are represented by the NA (not available) values. Most modeling functions in R offer options for dealing with missing values. You can go further with the pairwise or listwise deletion of missing values through methods such as multiple imputations. 

R datasets are mostly filled with empty or NaN or NA values which you need to clean.  The na.omit() in the R function removes the rows of data containing the NA value.

You can also use the function to check if the particular R object contains any NA value or not. Let’s discuss the method in detail. in r

To check if the value is NA in R, use the function. The is a built-in R function that returns TRUE if it finds NA value and FALSE if it does not find in the dataset. If the value is NA, the function returns TRUE, otherwise, returns FALSE.



The function takes an R Object to be tested.

Return value

The default method for applied to an atomic vector returns a logical vector of the same length as its argument x, containing TRUE for those elements marked NA or, for numeric or complex vectors, NaN, and FALSE otherwise.


data <- c(11, 21, 19, NA, 46, NA)



You can see that if the function encounters the NA values, it returns TRUE otherwise FALSE.

Using any() function with function

The any() is a built-in R function that returns whether any of the values are NA in the input object.

data <- c(11, 21, 19, NA, 46, NA)



[1] TRUE

In this example, any() function returns TRUE because the vector data contains at least one NA value. If it does not contain a single NA value then it returns FALSE.

data <- c(11, 21, 19, 46, 18)




When combined with the any() function with, it becomes a very powerful tool for dealing with missing data in a data set. 

That’s it for function in R.

Leave a Comment