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?

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

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

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.

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.

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.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

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.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.