Question 1

Suppose \(x = 1.1\), \(a = 2.2\), and \(b = 3.3\). Assign each expression to the value of the variable \(z\) and print the value stored in \(z\).

\[x^a^b\] \[(x^a)^b\] 3x3+2x2+1

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

# a
z <- x^a^b

# b
z <- (x^a)^b

# c
z <- 3*(x^3)+2*(x^2)+1

Question 2

# a
z <- c(seq(1:8), seq(7:1))
print(z)
##  [1] 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7
# b
z <- rep(x=seq(1:5), times=seq(1:5))
print(z)
##  [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
# c
z <- rep(x=seq(5,1), times=seq(1,5))
print(z)
##  [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1

Question 3

x <- runif(2)
print(x)
## [1] 0.09934142 0.05992009
r <- sqrt(x[1]^2 + x[2]^2)
theta <- atan(x[2]/x[1])

coords <- c(r,theta)
print(coords)
## [1] 0.1160135 0.5427495

Question 4

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

Question 5

num <- seq(1:100)

which(num %% 2 & num %% 3 & num %% 7)
##  [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