What is a repeat loop in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

What is a repeat loop in R?

What is a repeat loop in R?

This recipe explains what is a repeat loop in R

1

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 repeat loops in this recipe by demonstrating an example

Repeat loops are used when a block of code until a stop condition or break is met. It is an alternative to do-while in traditional programming languages.

Syntax:

repeat{ // Block of code that needs to be executed until the if condition speficied is met if (boolean_condition){ break } }

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

# Creating an iterator a = 2 ‚Äč # Using repeat loop repeat{ print(a^3) #increasing the iterator by one a=a+1 if(a<=7){ } } while(a<=6){ print(a^3) a=a+1 }
[1] 8
[1] 27
[1] 64
[1] 125
[1] 216

Relevant Projects

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Build a Similar Images Finder with Python, Keras, and Tensorflow
Build your own image similarity application using Python to search and find images of products that are similar to any given product. You will implement the K-Nearest Neighbor algorithm to find products with maximum similarity.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

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 Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

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.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.