1. Install the ISwR R package. Write the built-in dataset thuesen to a tab-separated textfile. View it with a text editor. Change the NA to . (period), and read the changed fileback into R.

#install ISwR
#install.packages("ISwR")
library(ISwR)
#call built-in data "thuesen"
head(thuesen)
##   blood.glucose short.velocity
## 1          15.3           1.76
## 2          10.8           1.34
## 3           8.1           1.27
## 4          19.5           1.47
## 5           7.2           1.27
## 6           5.3           1.49
write.table(thuesen, file = "results", quote = F, col.names = T, row.names = T, sep = "\t")
#open in text editor and manually change NA value to "." resave as "resultsfinal"
read.table("resultsfinal.txt")
##    blood.glucose short.velocity
## 1           15.3           1.76
## 2           10.8           1.34
## 3            8.1           1.27
## 4           19.5           1.47
## 5            7.2           1.27
## 6            5.3           1.49
## 7            9.3           1.31
## 8           11.1           1.09
## 9            7.5           1.18
## 10          12.2           1.22
## 11           6.7           1.25
## 12           5.2           1.19
## 13          19.0           1.95
## 14          15.1           1.28
## 15           6.7           1.52
## 16           8.6              .
## 17           4.2           1.12
## 18          10.3           1.37
## 19          12.5           1.19
## 20          16.1           1.05
## 21          13.3           1.32
## 22           4.9           1.03
## 23           8.8           1.12
## 24           9.5            1.7

2. The exponential growth of a population is described by this mathematical function:

Nt = N0 e^rt where Nt is the population size at time t, N0 is the initial population size, and r is the rateof growth or reproductive rate. Write an exponential growth function in R that alsogenerates a plot with time on the x axis and Nt on the y axis. Using that function createplots for 20 days assuming an initial population size of 10 individuals under three growthrate scenarios (0.5, 0.8, -0.1).

t<-1:20
r1<-(0.5)
r2<-(0.8)
r3<-(-0.1)
line0.5 <-(10*exp(r1*t))
line0.8 <-(10*exp(r2*t))
lineneg0.1 <-(10*exp(r3*t))

# plot the first curve by calling plot() function
# First curve is plotted
plot(t, line0.5, type="o", col="blue", pch="o", lty=1, ylim=c(0,1000), xlab = "Population Total", ylab = "Time (Days)" )

# Add second curve to the same plot by calling points() and lines()
# Use symbol '*' for points.
points(t, line0.8, col="red", pch="*")
lines(t, line0.8, col="red",lty=2)

# Add Third curve to the same plot by calling points() and lines()
# Use symbol '+' for points.
points(t, lineneg0.1, col="green",pch="+")
lines(t, lineneg0.1, col="green", lty=3)

3. Under highly favorable conditions, populations grow exponentially. Howeverresources will eventually limit population growth and exponential growth cannotcontinue indefinitely. This phenomenon is described by the logistic growth function:

Nt=K*N0/(N0+(K−N0)e^−rt) where K is the carrying capacity. Write a logistic growth function in R that alsogenerates a plot with time on the x axis and Nt on the y axis. Using that function createplots for 20 days assuming an initial population size of 10 individuals and a carryingcapacity of 1,000 individuals under three growth rate scenarios (0.5, 0.8, 0.4).

t<-1:20
r1<-(0.5)
r2<-(0.8)
r3<-(0.4)
line0.5 <-(1000*10)/(10+(1000-10)*exp(-r1*t))
line0.8 <-(1000*10)/(10+(1000-10)*exp(-r2*t))
line0.4 <-(1000*10)/(10+(1000-10)*exp(-r3*t))

# plot the first curve by calling plot() function
# First curve is plotted
plot(t, line0.5, type="o", col="blue", pch="o", lty=1, ylim=c(0,1100), xlab = "Population Total", ylab = "Time (days)" )

# Add second curve to the same plot by calling points() and lines()
# Use symbol '*' for points.
points(t, line0.8, col="red", pch="*")
lines(t, line0.8, col="red",lty=2)

# Add Third curve to the same plot by calling points() and lines()
# Use symbol '+' for points.
points(t, line0.4, col="green",pch="+")
lines(t, line0.4, col="green", lty=3)

4. Write a function (sum_n) that for any given value, say n, computes the sum of theintegers from 1 to n (inclusive). Use the function to determine the sum of integers from 1to 5,000.

n=5000
sum_n <- sum(1:n)
print(sum_n)
## [1] 12502500

5. Write a function (sqrt_round) that takes a number x as input, takes the square root,rounds it to the nearest whole number and then returns the result.

x = 5
sqrt_round <- round(sqrt(x), 0)
print(sqrt_round)
## [1] 2