Program flow

These commands allow you to direct where and how will your scripts evaluate based on the input conditions. For example, if a data column has missing data, you don't want to conduct the same test or you at least want to print a warning to the user.

Also there are loops that will allow you to do the same thing over and over again. Loops are useful for handeling multiple tables, outputting many graphs or randomising milions of data simulations. You probaly don't want to write each simulation as a single line.

Comparison

Comparing produces logical value or vectors (or matrices). Comparison uses following statements:


In [2]:
compared_num = 10
5 == compared_num
5 < compared_num
5 > compared_num
10 > compared_num
10 >= compared_num
10 < compared_num


FALSE
TRUE
FALSE
FALSE
TRUE
FALSE

Functions can also produce logical return.


In [5]:
nothing = NULL
is.null(nothing)
is.numeric(nothing)
is.character(nothing)


FALSE
FALSE
FALSE

We can negate results by using !


In [ ]:
!is.null(nothing)
10 != compared_num

if statement

Conditions are evaluated based on a logical vector.


In [ ]:
condition = TRUE
if(condition){
    print("It's true")
}

We can also use else statememt to do other stuff instead.


In [ ]:
condition = TRUE
if(condition){
    print("Its true")
} else {
    print("It'S sooo false")
}

Loops

Loops allow us to do bunch of stuff angain and again and again

For

While


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:

Let's combine all together


In [ ]:
games =  c("CS Files", "Terra Mystica", "Cosmic Encounter", "Pandemic", "Takenoko", "Survive", "Stronghold", "Bang")
is_good = function(name){
    bad_games = c("Bang", "Survive", "Stronghold")
    if()
}