官术网_书友最值得收藏!

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
主站蜘蛛池模板: 二手房| 新干县| 满洲里市| 柞水县| 霍城县| 华亭县| 荥阳市| 依兰县| 若羌县| 安陆市| 铁岭县| 汉中市| 光泽县| 牟定县| 西乡县| 柞水县| 涿鹿县| 巴青县| 晋城| 桂东县| 永仁县| 筠连县| 襄汾县| 自治县| 垣曲县| 遂川县| 安溪县| 濮阳县| 邵东县| 巴彦县| 调兵山市| 武穴市| 定远县| 滁州市| 额尔古纳市| 中牟县| 秦皇岛市| 任丘市| 刚察县| 佛学| 河北省|