Click here to return to the main page
1. This is question 1!
x <- 1.1 #Define variable
a <- 2.2
b <- 3.3
z <- x^(a^b) #run first equation
print(z) #print result
## [1] 3.61714
z <- (x^a)^b # run second equation
print(z)
## [1] 1.997611
z <- 3*x^3 +2*x^2 + 1 # run third equation
print(z)
## [1] 7.413
2. This is question 2!
v1 <- c(1:8, seq(7,1)) # set first vector
print(v1)
## [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
v2 <- rep(1:5, seq(1,5)) # set second vector
print(v2)
## [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
v3 <- rep(5:1, seq(1,5)) # set third vector
print(v3)
## [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1
3. This is question 3!
vector <- runif(2) #create cartesian coordinate
x = vector[1] #isolate X coordinate
y = vector[2] # isolate y coordinate
print(x) #print coordinates
## [1] 0.6007011
print(y)
## [1] 0.058782
r = sqrt(x^2+y^2) #calculate r value for polar coordinates
theta = atan(y/x) # calculate angle value for polar coordinates
print(r) # print results
## [1] 0.6035703
print(theta)
## [1] 0.09754509
4. This is question 4!
queue <- c("sheep", "fox", "owl", "ant") # set queue
# a. the serpent arrives and gets in line
queue <- c(queue, "serpent") # add serpent
print(queue)
## [1] "sheep" "fox" "owl" "ant" "serpent"
# b the sheep enters the ark
queue <- queue[-which(queue=="sheep")] #sheep enters ark
print(queue)
## [1] "fox" "owl" "ant" "serpent"
# c the donkey arrives and talks his way to the front of the line
queue <- c("donkey", queue) # donkey cuts line
print(queue)
## [1] "donkey" "fox" "owl" "ant" "serpent"
# d the serpent gets impatient and leaves
queue <- queue[-which(queue=="serpent")]
print(queue)
## [1] "donkey" "fox" "owl" "ant"
#e the owl gets bored and leaves
queue <- queue[-which(queue=="owl")]
print(queue)
## [1] "donkey" "fox" "ant"
#f the aphid arrives and the ant invites him to cut in line
queue <- append(queue, "aphid", after = which(queue=="ant")-1)
print(queue)
## [1] "donkey" "fox" "aphid" "ant"
#g Finally, determine the position of the aphid in the line
which(queue=="aphid")
## [1] 3
5. This is question 5!
q5 <- c(1:100) #set q5 to all integers 1-100
print(q5)
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
## [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
## [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
## [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
## [91] 91 92 93 94 95 96 97 98 99 100
q5 <- q5[q5%%2!=0 & q5%%3!=0 & q5%%7!=0] #only select numbers that are not divisible by 2, 3, or 7
print(q5)
## [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