- R Data Visualization Cookbook
- Atmajitsinh Gohil
- 145字
- 2021-08-06 19:21:08
Writing if else statements in R
We often use if
statements in MS Excel, but we can also write a small code to perform simple tasks in R.
How to do it…
The logic for if else
statements is very simple and is as follows:
if(x>3){ print("greater value") }else { print("lesser value") }
We can copy and paste the preceding statement in the R console or write a function that makes use of the if else logic.
How it works…
The logic behind if
else
statements is very simple. The following lines clearly state the logic:
if(condition){ #perform some action }else { #perform some other action }
The preceding code will check whether x is greater than or less than 3, and simply print it. In order to get the value, we type the following in the R command window:
x = 2
推薦閱讀
- Facebook Application Development with Graph API Cookbook
- Visual Studio 2012 Cookbook
- C語言程序設計(第2版)
- Scratch 3.0少兒編程與邏輯思維訓練
- Mastering ServiceNow(Second Edition)
- Visual Basic程序設計教程
- Mastering Xamarin.Forms(Second Edition)
- 區塊鏈項目開發指南
- C指針原理揭秘:基于底層實現機制
- Simulation for Data Science with R
- 寫給大家看的Midjourney設計書
- Spring Boot從入門到實戰
- The Applied Data Science Workshop
- INSTANT EaselJS Starter
- 現代JavaScript編程:經典范例與實踐技巧