Copy and paste the following code to your R Studio platform or R version:

# The if statement

rnorm(1)

# creating a number derived from a sample that follows the
# normal distribution and that is the function of creating that

rnorm(10, mean = 0, sd = 1)
# here we define also the mean and the sttandard deviation desired

rm(answer)
x <- rnorm(1)
if (x > 1) {

answer <- “It is greater than 1 indeed!”

} else {

answer <- “It is less or equal to 1!”

}
print(answer)

# If else if statement –nested if statement

rm(answer)
x <- rnorm(1)

if (x > 1) {

answer <- “It is greater than 1 indeed!”

} else if (x >= -1) {

answer <- “It is between -1 and 1!”

} else {

answer <- “Less than -1!”
}

print(answer)

Posted by Dimitris

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s