# Introduction exercises

# 1. Create two objects a and b, assigning them the values 4 and 10 respectively
a <- 4
b <- 10
# 1.1. Create the object c as the product of a and b
c <- a*b
# 1.2. Check whether c is less than 40
c < 40
# 2. Run and interpret: 7 - 2 + (8 / 2 < 1)
7 - 2 + (8 / 2 < 1)
# first math in brackets 8/2, then 4 < 1 = FALSE so the result of the () is 0
# then 7 - 2 + 0 = 5

# 4. Create two objects d and e, assigning them the values 3 and 8 respectively
# 4.1. check whether d*e is an even number ? %%
d <- 3
e <- 8

# remainder of division
d*e%%2 == 0

# 5. Write a statement to evaluate the following condition:
# "x is a number between -10 and -8 or it is a number between 8 and 10"
x <- 9
(x > -10 & x < -8) | (x > 8 & x < 10)

# 5.1. if you did not use the abs() function, write an equivalent
# statement using abs().
x <- -9
abs(x) < 10 & abs(x) > 8

# 6. Run the following logical operations between strings 
# and try to predict the result before running the code
"hey" == "Hey"
"1" == 1
"a" > "b"
"dog" > "zebra"


# Not mandatory, we will se functions in few minutes
# 6.1. Repeat the comparisons in case-insensitive mode
# by applying tolower() or toupper() to the strings before comparing them.
# ?tolower
"hey" == tolower("Hey")
"R" == toupper("r")
"SPSS" != toupper("spss")




