Introduction

I would like to learn more about how spatial data is used for infrastructure projects. A potential research project could be how GIS is utilized to prioritize sites for sustainable energies such as wind, solar, and green hydrogen.

Data

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

avrspeed <- mean(cars$dist)

avrspeed
## [1] 42.98
# 2. compute the max distance of the car

maxdis <- max(cars$dist)

maxdis
## [1] 120
# 3. add a new variable to the cars dataset called "mult" that is the product of speed and distance

cars$mult <- (cars$speed * cars$dist)
# 4. compute the minumun of this new column

min(cars$mult)
## [1] 8
minnewcol <- min(cars$mult)

minnewcol
## [1] 8
# 5. create a NEW dataset where all rows in which speed is less than 10 to 0

cars2 <- subset(cars, cars$speed < 10)

# 6. compute the mean of speed in this new dataset

mean(cars2$speed)
## [1] 6.5
avrspeedcars2 <- mean(cars2$speed)

avrspeedcars2
## [1] 6.5

Visualization

Go back to the original cars dataset for these visualizations.

# 7. plot a histogram of speed 

hist(cars$speed,
     xlab = "Speed",
     main = "Car Speed")

# 8. plot a histogram of distance and add the title "Car Distance"

hist(cars$dist,
     xlab = "Distance",
     main = "Car Distance")

# 9. plot speed versus distance

plot(cars$speed ~ cars$dist, data = cars,
     xlab = "Distance",
     ylab = "Speed",
     main = "Speed vs. Distance")

# 10. add axis labels and a title to this plot

Knit your document to a .html file. Submit this knitted document on Canvas.