___________________________________________

Questions 1: Suppose x = 1.1, a = 2.2, and b = 3.3. Assign each expression to the value of the variable zand print the value stored in z.

a. \[x^{a^b}\]

# assign value to variables:
x=1.1
a=2.2
b=3.3

#A.
proba<-x^(a^b)
print(proba)
## [1] 3.61714

b. \[(x^a)^b\]

probb<-(x^a)^b
print(probb)
## [1] 1.997611

c. \[3x^3 + 2X^2 + 1\]

probc<-(3*(x^3))+2*(x^2)+1
print(probc)
## [1] 7.413

d. The digit in the second place of z

##A.
floor((proba %% 1) *10)
## [1] 6
##B. 
floor((probb %% 1) * 10)
## [1] 9
##C. 
floor((probc %% 1)*10)
## [1] 4

Question 2:Using the rep and seq functions, create the following vectors

A. (1,2,3,4,5,6,7,8,7,6,5,4,3,2,1)
c(seq(1:8),rep(7:1))
##  [1] 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
B. (1,2,2,3,3,3,4,4,4,4,5,5,5,5,5)
rep(1:5, c(1,2,3,4,5))
##  [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
C. (5,4,4,3,3,3,2,2,2,2,1,1,1,1,1)
rep(5:1, c(1,2,3,4,5))
##  [1] 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1

Question 3: 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 or in your calculus textbook).

i<-runif(2)
i[1]
## [1] 0.06418897
i[2]
## [1] 0.3820639
x = i[1]
print(x)
## [1] 0.06418897
y = i[2]

r= sqrt((x^2)+(y^2))
print(r)
## [1] 0.3874185
#theta = "t"
t=atan(y/x)
print(t)
## [1] 1.404345

Question 4: Suppose that queue <- c(“sheep”, “fox”, “owl”, “ant”) and that 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 the queue successively as

queue <-c("sheep", "fox", "owl", "ant")
a.
quA <-c(queue, "serpent")
print(quA)
## [1] "sheep"   "fox"     "owl"     "ant"     "serpent"
b.
quB<-quA[-1]
print(quB)
## [1] "fox"     "owl"     "ant"     "serpent"
c.
quC<-c("donkey", quB)
print(quC)
## [1] "donkey"  "fox"     "owl"     "ant"     "serpent"
d.
quD<-quC[-5]
print(quD)
## [1] "donkey" "fox"    "owl"    "ant"
e.
quE <-quD[-3]
print(quE)
## [1] "donkey" "fox"    "ant"
f.
quF<-c(quE[-3], "aphid", "ant")
print(quF)
## [1] "donkey" "fox"    "aphid"  "ant"
g.
quG <- which(quF == "aphid")
print(quG)
## [1] 3

Question 5:Use R to create a vector of all of the integers from 1 to 100 that are not divisible by 2, 3, or 7

z5<-1:100
z5[z5%%2!=0 & z5%%3!=0  &  z5%%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
## [24] 83 85 89 95 97

Question 6: Create a vector z of 1000 random uniform numbers

a. create a vector that contains 3 numbers: the proportion of the numbers in z that are less than 0.10, greater than 0.90, and between 0.45 and 0.55.
z6 <- runif(1000)
z6v <- c(mean(z6 < 0.1), mean(z6 > 0.9), mean(z6 > 0.45 & z6 < 0.55))
print(z6v)
## [1] 0.107 0.093 0.109
b. Making successive copies of z, transform your vector of uniform numbers in the following ways
b1. log (base 10) of z
z6log<-log10(z6)
head(z6log)
## [1] -0.009875105 -0.074994705 -0.425757388 -0.004122771 -0.010340087
## [6] -0.555903304
z6vlog<-c(mean(z6log < 0.1), mean(z6log > 0.9), mean(z6log >0.45 & z6log<0.55))
print(z6vlog)          
## [1] 1 0 0

b2. z^2

z6sq<-(z6)^2
head(z6sq)
## [1] 0.95554202 0.70796305 0.14076193 0.98119304 0.95349809 0.07730247
z6vsq<-c(mean(z6sq < 0.1), mean(z6sq > 0.9), mean(z6sq >0.45 & z6sq<0.55))
print(z6vsq)
## [1] 0.322 0.051 0.071

b3. exp^z

z6exp<-exp(z6)
head(z6exp)
## [1] 2.657852 2.319625 1.455257 2.692720 2.655073 1.320530
z6vexp<-c(mean(z6exp < 0.1), mean(z6exp > 0.9), mean(z6exp >0.45 & z6exp<0.55))
print(z6vexp)
## [1] 0 1 0

b4. square root of z

z6sqrt<-sqrt(z6)
head(z6sqrt)
## [1] 0.9886952 0.9172815 0.6125215 0.9952647 0.9881661 0.5272886
z6vsqrt<-c(mean(z6sqrt < 0.1), mean(z6sqrt > 0.9), mean(z6sqrt >0.45 & z6sqrt<0.55))
print(z6vsqrt) 
## [1] 0.008 0.194 0.098

—————————————–