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 <- 1.1
a <- 2.2
b <- 3.3

#a)
z <- ((x)^a)^b
print(z)
## [1] 1.997611
z <- x^a^b
print(z)
## [1] 3.61714
#(unsure how to interpret, giving both potential responses)

#b)
z <- (x^a)^b
print(z)
## [1] 1.997611
#c)
z <- (3 * x^3) + (2*x^2) + 1
print(z)
## [1] 7.413
  1. Using the rep and seq functions, create the following vectors:
#a
z <- c(rep(1:8),rep(7:1))

print(z)
##  [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
#b
z <- rep(1:5, 1:5)
z
##  [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
#c
z <- rep(5:1, 1:5)
z
##  [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1
  1. Create a vector of two random uniform numbers. In a spatial map, these can be interpreted as x and y coordinates that give the location of an individual (such as a marked forest tree in a plot that has been mapped). Using one of R’s inverse trigonometry functions (asin(), acos(), or atan()), convert these numbers into polar coordinates (If you don’t know what polar coordinates are, read about them on the web here, here, or in your calculus textbook).
random_uniform_numbers <- runif(2) 
random_uniform_numbers
## [1] 0.5523538 0.2990678
random_number1 <- 0.53610015
random_number2 <- 0.06247857

radius <- sqrt((random_number1^2)+(random_number2^2))
radius
## [1] 0.5397286
theta <- atan(random_number1 / random_number2)
theta
## [1] 1.454777
#x = random_number1 * cos(theta)
#y = random_number1 * sin(theta)

xcoord <- radius * cos(theta)
ycoord <- radius * sin(theta)
xcoord
## [1] 0.06247857
ycoord
## [1] 0.5361001
polarcoords <- c(xcoord,ycoord)
polarcoords
## [1] 0.06247857 0.53610015
  1. Create a vector queue <- c(“sheep”, “fox”, “owl”, “ant”) where queue represents the animals that are lined up to enter Noah’s Ark, with the sheep at the front of the line. Using R expressions, update queue as:
  1. the serpent arrives and gets in line;
  2. the sheep enters the ark;
  3. the donkey arrives and talks his way to the front of the line;
  4. the serpent gets impatient and leaves;
  5. the owl gets bored and leaves;
  6. the aphid arrives and the ant invites him to cut in line.

Finally, determine the position of the aphid in the line.

#creating the line
queue <- c("sheep", "fox", "owl", "ant")

#adding the serpent to the queue
queue <-append(queue, "serpent")

queue
## [1] "sheep"   "fox"     "owl"     "ant"     "serpent"
#removing the sheep from the queue
queue <-c(queue[2:5])

queue
## [1] "fox"     "owl"     "ant"     "serpent"
#adding the donkey to the front of the line
queue <- c("donkey", queue)

queue
## [1] "donkey"  "fox"     "owl"     "ant"     "serpent"
#removing the serpent from the queue
queue <- c(queue[1:4])

queue
## [1] "donkey" "fox"    "owl"    "ant"
#removing the owl from the queue 
queue <- c(queue[1],queue[2],queue[4])

queue
## [1] "donkey" "fox"    "ant"
#adding the aphid to the front of the line 

queue <- c(queue[1:2], "aphid", queue[3])

queue
## [1] "donkey" "fox"    "aphid"  "ant"
#finding the aphids position in line 
aphid_position <- which(queue == "aphid")

print(paste("Aphid Place in Line:", aphid_position))
## [1] "Aphid Place in Line: 3"
  1. Use R to create a vector of all of the integers from 1 to 100 that are not divisible by 2, 3, or 7. You will need one of the arithmetic operators on this cheat sheet.
#creating initial vector 1:100
integer_vector_100 <- seq(1:100)

#filtering list according to request
not_dividable_237 <- which(! integer_vector_100%%2== 0 & ! integer_vector_100%%3== 0 & ! integer_vector_100%%7==0)

print(not_dividable_237)
##  [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