My research interests include climate sciences and the impact that humans have in relationship to climate change and its environmental stressors. For my research project, I would like to explore topics such as how vulnerable species will respond to environmental changes, or how the health of an urban ecosystem compares to a more natural ecosystem with little to no human impact.
This code loads the cars dataset from the
datasets package. This is a special package - by loading
the datasets package, we automatically load a number of toy
datasets used for teaching R. Run this code chunk to load
the data in your environment.
library(datasets)
head(cars)
## speed dist
## 1 4 2
## 2 4 10
## 3 7 4
## 4 7 22
## 5 8 16
## 6 9 10
head() is a good function to quickly visualize your
data.
# 1. compute the mean speed of the car
mean(cars$speed)
## [1] 15.4
# 2. compute the max distance of the car
max(cars$dist)
## [1] 120
# 3. add a new variable to the cars dataset called "mult" that is the product of speed and distance
cars2 <- cars
cars2$mult <- cars2$speed * cars2$dist
# 4. compute the minumun of this new column
min(cars2$mult)
## [1] 8
# 5. create a NEW dataset where all rows in which speed is less than 10 to 0
cars3 <- subset(cars2, cars2$speed<10)
# 6. compute the mean of speed in this new dataset
mean(cars3$speed)
## [1] 6.5
Go back to the original cars dataset for these
visualizations.
# 7. plot a histogram of speed
hist_speed <- hist(cars$speed)
# 8. plot a histogram of distance and add the title "Car Distance"
hist_dist <- hist(cars$dist, main= "Car Distance")
# 9. plot speed versus distance
speed_vs_dist <- plot(speed~dist, data=cars)
# 10. add axis labels and a title to this plot
speed_vs_dist_lab <- plot(speed~dist, data=cars, main= "Speed vs Distance", ylab= "Speed", xlab= "Distance")
Knit your document to a .html file. Submit this knitted document on Canvas.