---
layout: post
title: "How to write an if else block in R and how its different from ifelse and if_else (CC175)"
blurb: "When to use if...else vs. ifelse or if_else"
author: "PD Schloss"
date: 2022-01-03 11:00
comments: false
youtube: UGYGEAv-b0s
start_hash: 9ef329fe063fdf15a61b4dbf83b3ce0962f850b3
end_hash: 12364b6b12caba562d5d0418a99d913a5bd80db0
---

An if else block is an effective tool for using conditional statements to control the flow of data through an R script. In this Code Club, Pat gives a tutorial on how to write blocks containing a single if statement, if else statements and if else if else statements. He'll also demonstrate how this approach is different from using the ifelse and if_else functions. This is part of a series of videos demonstrating how to functions from base R to make these data compatible with tools from the tidyverse


<iframe style="margin: 0 auto;display:block;" width="560" height="315" src="https://www.youtube.com/embed/{{ page.youtube }}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>


## Code

You can browse the state of the repository at the
* [beginning of the episode](https://github.com/riffomonas/distances/tree/{{ page.start_hash }})
* [end of the episode](https://github.com/riffomonas/distances/tree/{{ page.end_hash }})
