How to drop null values in a list in R

This recipe helps you drop null values in a list in R

Recipe Objective

How to drop null values in a list?

Null values are the empty values/missing values at a particular position in a list or in a cell of a dataframe. A null value must be either replaced with an appropriate value or totally removed from a list. Null values must be dealt with in the beginning as a step of data cleaning in order to avoid any further miscalculation in the statistical calculations. The following recipe demonstrates an example of how to drop null values in R.

Build a Chatbot in Python from Scratch!

Step 1 - Define a list

x <- list(1,NULL,NULL,5,10,63,NULL,89,NULL,NULL,36,15,78,25,NULL) print(x)

Step 2 - Using the Filter(Negate()) function

The Negate() removes all the null values in a list. Syntax - Filter(Negate(is.null),list)

y <- Filter(Negate(is.null), x) # filters out all the null values from the list print(y)

 "Output of the code :"
[[1]]
[1] 1

[[2]]
[1] 5

[[3]]
[1] 10

[[4]]
[1] 63

[[5]]
[1] 89

[[6]]
[1] 36

[[7]]
[1] 15

[[8]]
[1] 78

[[9]]
[1] 25

{"mode":"full","isActive":false}

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

House Price Prediction Project using Machine Learning in Python
Use the Zillow Zestimate Dataset to build a machine learning model for house price prediction.

Locality Sensitive Hashing Python Code for Look-Alike Modelling
In this deep learning project, you will find similar images (lookalikes) using deep learning and locality sensitive hashing to find customers who are most likely to click on an ad.

Build a Hybrid Recommender System in Python using LightFM
In this Recommender System project, you will build a hybrid recommender system in Python using LightFM .

Build CI/CD Pipeline for Machine Learning Projects using Jenkins
In this project, you will learn how to create a CI/CD pipeline for a search engine application using Jenkins.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Image Classification Model using Transfer Learning in PyTorch
In this PyTorch Project, you will build an image classification model in PyTorch using the ResNet pre-trained model.

Word2Vec and FastText Word Embedding with Gensim in Python
In this NLP Project, you will learn how to use the popular topic modelling library Gensim for implementing two state-of-the-art word embedding methods Word2Vec and FastText models.

Build Piecewise and Spline Regression Models in Python
In this Regression Project, you will learn how to build a piecewise and spline regression model from scratch in Python to predict the points scored by a sports team.

Learn Object Tracking (SOT, MOT) using OpenCV and Python
Get Started with Object Tracking using OpenCV and Python - Learn to implement Multiple Instance Learning Tracker (MIL) algorithm, Generic Object Tracking Using Regression Networks Tracker (GOTURN) algorithm, Kernelized Correlation Filters Tracker (KCF) algorithm, Tracking, Learning, Detection Tracker (TLD) algorithm for single and multiple object tracking from various video clips.

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.