1. Assigning each expression to the value of the variable z and print the value stored in z

x <-1.1
a <- 2.2
b <- 3.3

# a 
z <-x^(a^b) 
print(z)
## [1] 3.61714
#b
z<- (x^a)^b
print(z) 
## [1] 1.997611
#c
z<-(3*x^3)+(2*x^2)+1
print(z)
## [1] 7.413

2.Using the rep and seq functions, create the following vectors

my_vectorA <- c(seq(1, 8, by = 1), seq(7, 1, by = -1))
print(my_vectorA)
##  [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
my_vectorB<- rep(1:5, 1:5)
print(my_vectorB)
##  [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
my_vectorC<- rep(5:1, 5:1)
print(my_vectorC)
##  [1] 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1

3.Polar coordinates

set.seed(1)
coor <- runif(2) #Creating a vector of two random uniform numbers
print(coor)
## [1] 0.2655087 0.3721239
x <- coor[1]
print(x)
## [1] 0.2655087
y <- coor[2]
print(y)
## [1] 0.3721239
#calculating the radius 
radius <- sqrt(x^2 + y^2)
print(radius)
## [1] 0.4571335
#calculating the theta with atan() function
theta <- atan(y / x)
print(theta)
## [1] 0.9510704

4.Noah’s Ark

queue <- c("sheep", "fox", "owl", "ant")
print(queue)
## [1] "sheep" "fox"   "owl"   "ant"
#the serpent arrives and gets in line
queue<-c(queue,"serpent") 
print(queue)
## [1] "sheep"   "fox"     "owl"     "ant"     "serpent"
#the sheep enters the ark
queue <- queue[-which(queue == "sheep")]
print(queue)
## [1] "fox"     "owl"     "ant"     "serpent"
#the donkey arrives and talks his way to the front of the line
queue<-c("donkey", queue)
print(queue)
## [1] "donkey"  "fox"     "owl"     "ant"     "serpent"
#the serpent gets impatient and leaves
queue <- queue[-which(queue == "serpent")]
print(queue)
## [1] "donkey" "fox"    "owl"    "ant"
#the owl gets bored and leaves
queue <- queue[-which(queue == "owl")]
print(queue)
## [1] "donkey" "fox"    "ant"
#the aphid arrives and the ant invites him to cut in line.
which(queue == "ant")
## [1] 3
queue <- c(queue[1:(3-1)], "aphid", queue[3:length(queue)])
print(queue)
## [1] "donkey" "fox"    "aphid"  "ant"
#Finally, determine the position of the aphid in the line.
which(queue == "aphid")
## [1] 3

5.Using arithmetic operators to filter a vector to get a sequence from 1 to 100 with numbers not divisibles by 2, 3, or 7

X <-1:100
Xfiltered <- X[!(X %% 2 == 0 | X %% 3 == 0 | X %% 7 == 0)]
print(Xfiltered)
##  [1]  1  5 11 13 17 19 23 25 29 31 37 41 43 47 53 55 59 61 65 67 71 73 79 83 85
## [26] 89 95 97