How to filter a list array based on two or more conditions in R

This recipe helps you filter a list array based on two or more conditions in R

Recipe Objective

How to filter a list/array based on two or more conditions?

A list.filter () function is used to filter out specified elements from a list that returns TRUE value for the given condition (s). Filter () helps to reduce a huge dataset into small chunks of datasets. Syntax — list.filter (data, condition) This recipe illustrates an example of filtering and list based on multiple conditions.

Learn How to use XLNet for Text Classification

Step 1 - Import necessary library

install.packages('rlist') library(rlist)

Step 2 - Define a list

data <- list(name = c("Sid","John","Blake","Sam","Ray"), age = c(22,26,29,30,35), profession = c("Arts","Music","Music","Art","Dance"), location = c("Canada","India","USA","USA","Ireland")) data

"List is :" 

print(data)
$name
[1] "Sid"   "John"  "Blake" "Sam"   "Ray"  

$age
[1] 22 26 29 30 35

$profession
[1] "Arts"  "Music" "Music" "Art"   "Dance"

$location
[1] "Canada"  "India"   "USA"     "USA"     "Ireland"

Step 3 - Apply list.filter()

str(list.filter(data$age > 25 & data$profession == "Music" & data$location == "USA" ))

 "Output of code is :" 
 logi [1:5] FALSE FALSE TRUE FALSE FALSE

{"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

Learn to Build a Siamese Neural Network for Image Similarity
In this Deep Learning Project, you will learn how to build a siamese neural network with Keras and Tensorflow for Image Similarity.

AWS Project to Build and Deploy LSTM Model with Sagemaker
In this AWS Sagemaker Project, you will learn to build a LSTM model on Sagemaker for sales forecasting while analyzing the impact of weather conditions on Sales.

Build a Face Recognition System in Python using FaceNet
In this deep learning project, you will build your own face recognition system in Python using OpenCV and FaceNet by extracting features from an image of a person's face.

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.

ML Model Deployment on AWS for Customer Churn Prediction
MLOps Project-Deploy Machine Learning Model to Production Python on AWS for Customer Churn Prediction

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

NLP Project to Build a Resume Parser in Python using Spacy
Use the popular Spacy NLP python library for OCR and text classification to build a Resume Parser in Python.

BERT Text Classification using DistilBERT and ALBERT Models
This Project Explains how to perform Text Classification using ALBERT and DistilBERT

Recommender System Machine Learning Project for Beginners-3
Content Based Recommender System Project - Building a Content-Based Product Recommender App with Streamlit