How to use where loops in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to use where loops in R?

How to use where loops in R?

This recipe helps you use where loops in R

0

Recipe Objective

Loops are an important feature in R-language. It helps us to iterate through vectors, lists and process required functions to its elements. They help us to implement complex logic which requires a repetitive step. There are three different loops in R:

  1. For loops
  2. While loops
  3. Repeat loops

Each of these loops has its own use cases. We will focus on While loops in this recipe by demonstrating an example

While loops are used when a block of code needs to be executed until a certain boolean expression specified is FALSE.

Syntax:

while (boolean_expression){ // Block of code that needs to be executed }

Example: To print the cubes of all the numbers starting from 2 to 6

# Creating an iterator a = 2 ​ while(a<=6){ print(a^3) #increasing the iterator by one a=a+1 }
[1] 8
[1] 27
[1] 64
[1] 125
[1] 216

Relevant Projects

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

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.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

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.

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.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.