How to find if a vector has nan value in it?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

# How to find if a vector has nan value in it?

This recipe helps you find if a vector has nan value in it

0

## Recipe Objective

An NAN value in R represents “NOT A NUMBER”, It is basically any numeric calculation with an undefined result, such as ‘0/0’. This exists only in vectors with numeric datatype. Even one NAN value in a vector causes difficulty to carry out calculations. Hence, we need to remove or replace it before carrying out any calculation.

Before we actually remove or replace them, we need to check whether there is an NAN number in a vector and for this we use is.nan() function.

This recipe demonstrates how to find if a vector has NAN values.

## Step 1: Creating 2 vectors

We create two vectors, one with NAN values and the other without it.

a = c(2,5,8,20,NaN, 35,NaN) ​ b = c(2,5,8,20,75,35,100)

## Step 2: Checking for NaN values

we use any() and is.nan() function to check for NaN values. It returns a logical value TRUE even if 1 Nan value is present.

#checking for NaN values in "a" vector any(is.nan(a))
TRUE
#checking for NaN values in "b" vector any(is.nan(b))
FALSE

#### Relevant Projects

##### Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

##### Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

##### Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

##### Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

##### German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

##### Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

##### Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

##### Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

##### Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

##### Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.