Step 1

x <- 1.1
a <- 2.2
b <- 3.3
z <- c(x^a^b, (x^a)^b, 3*x^3 + 2*x^2 + 1)
print(z)
## [1] 3.617140 1.997611 7.413000

The values 1.1, 2.2, and 3.3 were assigned to variables x, a, and b respectively. The values of the three expressions were then assigned to z using the c() function.

Step 2

vec_2a <- c(seq(1:8), seq(from=7, to=1))
print(vec_2a)
##  [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
vec_2b <- rep(1:5, times=1:5)
print(vec_2b)
##  [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
vec_2c <- rep(1:5, times=5:1)
print(vec_2c)
##  [1] 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5

Vectors from steps 2a, 2b, and 2c, are printed. Vector 2a combines a sequence from 1 to 8 with one from 7 to 1. Vector 2b repeats numbers 1 to 5 from 1 time to 5 times. Vector 2c switches the times= from 1:5 to 5:1 to create the opposite pattern of repetition

Step 3

xy_coordinates <- runif(2)
x_cor <- xy_coordinates[1]
y_cor <- xy_coordinates[2]

r_cor <- sqrt(x_cor^2 + y_cor^2)
print(r_cor)
## [1] 0.6477794
theta_cor <- atan(y_cor/x_cor) 
print(theta_cor)
## [1] 1.257917

The runif(2) creates 2 uniform numbers in a vector, and x_cor and y_cor are assigned the two different values from the vector. The r and theta coordinates are then calculated using the sqrt() function to calculate r from the square root and the atan() function to calculate theta from the arctangent.

Step 4

queue <- c("sheep", "fox", "owl", "ant")
print(queue) #starting queue
## [1] "sheep" "fox"   "owl"   "ant"
queue <- c(queue, "serpent")
print(queue) #a
## [1] "sheep"   "fox"     "owl"     "ant"     "serpent"
queue <- queue[2:5]
print(queue) #b
## [1] "fox"     "owl"     "ant"     "serpent"
queue <- c("donkey", queue)
print(queue) #c
## [1] "donkey"  "fox"     "owl"     "ant"     "serpent"
queue <- queue[1:4]
print(queue) #d
## [1] "donkey" "fox"    "owl"    "ant"
queue <- c(queue[1:2], queue[4])
print(queue) #e
## [1] "donkey" "fox"    "ant"
queue <- c(queue[1:2], "aphid", queue[3])
print(queue) #f
## [1] "donkey" "fox"    "aphid"  "ant"
which(queue=="aphid") #g
## [1] 3

The c() function is used throughout the steps to combine the queue or parts of the queue (using brackets and the numbering of the vector elements) with new elements or other parts of the queue. The new queue is printed after each step. At the end, the which() function is used to ask what position the aphid has in the vector.

Step 5

s <- seq(1:100)
s2 <- which(s%%2 != 0 & s%%3 != 0  & s%%7 != 0)
print(s2)
##  [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

The variable s is a sequence of all the integers between 1 and 100, and s2 finds which of those values do not have a remainder of 0 when divided by 2, 3, and 7.