Question 4
queue <- c("sheep","fox","owl","ant")
print(queue)
## [1] "sheep" "fox" "owl" "ant"
## a. the serpent arrives and gets in line;
queue <- c(queue,"serpent")
print(queue)
## [1] "sheep" "fox" "owl" "ant" "serpent"
## b. the sheep enters the ark;
queue <- queue[-1]
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)
print(queue)
## [1] "donkey" "fox" "owl" "ant" "serpent"
## d. the serpent gets impatient and leaves;
queue <- queue[-5]
print(queue)
## [1] "donkey" "fox" "owl" "ant"
## e. the owl gets bored and leaves;
queue <- queue[-3]
print(queue)
## [1] "donkey" "fox" "ant"
## f. the aphid arrives and the ant invites him to cut in line.
queue <- c(queue,"aphid")
print(queue)
## [1] "donkey" "fox" "ant" "aphid"
## g. Finally, determine the position of the aphid in the line.
which(queue=="aphid")
## [1] 4
Question 5
z <- c(1:100)
print(z)
## [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
# finding values of z not divisible 2,3, or 7
x <- which(z %% 2 & z %% 3 & z %% 7)
print(x)
## [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