Monday, April 17, 2023

R Tutorial Playlist - If else, ifelse

 Whit this episode, we are starting with flow control subject, and the first flow control mechanism we are going to cover is if else statement.

if(a>10){

    'statement a'

}else if(a=10){

    'statement b'

}else{

    'statement c'

}

With if(a>10) we are making first condition. If a>10 is true, 'statement a' is going to be executed, if is not, execution is jumping to second condition. Second and every other condition, except first one, goes with else if keyword. If second condition is true, 'statement b' is going to be executed, else 'statement c' is going to be executed. Every execution statement must be in within scopes {}.

There is one more way to use if else loop and that is with function:

ifelse('first condition', 'statement a', 'statement b')

First argument is actual condition, second is statement that is going to be executed if condition is true and third argument is statement that is going to be executed if condition is false.

In this episode, we covered one more subject and that is function invisible(). This function is going to prevent printing of every statement provided as the argument.

Video tutorial link, below:



No comments:

Post a Comment