Question One
A.
z <- 1.1 ^ 2.2 ^ 3.3
print(z)
## [1] 3.61714
B.
z <- (1.1 ^ 2.2) ^ 3.3
print(z)
## [1] 1.997611
C.
z <- 3 * 1.1 ^ 3 + 2 * 1.1 ^ 2 + 1
print(z)
## [1] 7.413
Question Two
A.
x <- c(seq(1, 7), 8, seq(7,1))
print(x)
## [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
B.
y <- seq(1:5)
print(y)
## [1] 1 2 3 4 5
rep(x=y, times=y)
## [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
C.
c <- rep(5:1)
print(c)
## [1] 5 4 3 2 1
rep(x=c, times=1:5)
## [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1
Question Three
#let's set seed so our values don't keep changing
set.seed(10)
#define x and y
x <- runif(1)
print(x)
## [1] 0.5074782
y <- runif(1)
print(y)
## [1] 0.3067685
# let's find r
r <- sqrt(x ^ 2 + y ^ 2)
print(r)
## [1] 0.5929933
# let's find theta
theta <- -asin(y/r)
print(theta)
## [1] -0.5437188
Question four
A.
#make queue
queue <- c("sheep", "fox", "owl", "ant")
print(queue)
## [1] "sheep" "fox" "owl" "ant"
#add the serpent
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[-5]
print(queue)
## [1] "donkey" "fox" "owl" "ant"
E.
queue <- queue[-3]
print(queue)
## [1] "donkey" "fox" "ant"
F.
queue <- c(queue[1], queue[2], "aphid", queue[3])
print(queue)
## [1] "donkey" "fox" "aphid" "ant"
G.
which(queue == "aphid")
## [1] 3
Question 5
vec <- seq(1:100)
which(!(vec %% 2 == 0 | vec %% 3 == 0 | vec %% 7 == 0))
## [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