How to write if else in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to write if else in R?

How to write if else in R?

This recipe helps you write if else in R

Recipe Objective

How to write a if else condition in R ? Conditional statements control the flow of the program. In if-else condition, the if () statement is executed when the condition is TRUE. If the expression returns a FALSE value, then the else() statement is executed. This recipe demonstrates an example of an if-else statement..

Step 1- Create a vector

x <- c(list(123,2.5,"hello"))

Step 2 - if else statement

if ("hi" %in% x){ print("hi present in x") } else { print("hi not present in x") }
"Output of the code is hi not present in x"  

Step 3- Nested if-else statement

Nested if-else statement executes only that statement which returns TRUE value.

if (13 %in% x){ print("13 is present in x") } else if (123 %in% x){ print("123 is present in x") } else{ print("not present in x") }
 "Output of the code is 123 is present in x" 

Relevant Projects

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.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

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 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.

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.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.

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.

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.