Introduction

My research interests focus on perceptions of crowding and identifying indicators impacting visitor experiences. My thesis research uses NVUM data collected across US forest service sites to identify the relationship between crowding and visitor satisfaction in different regions across the country. Assuming these variables are directly related, I think it would be really cool to combine crowding and satisfaction level data from the NVUM survey, connect that with spatial data, and then create a program/code that could then estimate the average satisfaction level of a site based on spatial aspects (proximity to a highly-populated area, etc.).

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
avg_speed <- mean(cars$speed)
avg_speed
## [1] 15.4
# 2. compute the max distance of the car
max_dist <- max(cars$dist)
max_dist
## [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_mult <- min(cars$mult)
min_mult
## [1] 8
# 5. create a NEW dataset where all rows in which speed is less than 10 to 0
speed_slow <- subset(cars,cars$speed<10)
speed_slow
##   speed dist mult
## 1     4    2    8
## 2     4   10   40
## 3     7    4   28
## 4     7   22  154
## 5     8   16  128
## 6     9   10   90
# 6. compute the mean of speed in this new dataset
avg_speed_slow <- mean(speed_slow$speed)
avg_speed_slow
## [1] 6.5

Visualization

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.