Answer the following questions and/or complete the exercises in
RMarkdown. Please embed all of your code and push the final work to your
repository. Your report should be organized, clean, and run free from
errors. Remember, you must remove the # for any included
code chunks to run.
library("tidyverse")
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.0 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.2 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
In order to answer the questions below, you will need to do a little online research.
1. Make three new vectors that show the name, height in feet, and height in meters of the five tallest mountains in the world.
mountain_name <- c("Mount Everest", "K2", "Kangchenjunga", "Lhotse", "Makalu")
height_feet <- c(29029, 28251, 28169, 27940, 27838)
height_meters <- c(8848, 8611, 8586, 8516, 8485)
2. Combine these vectors into a data frame called
mountains.
mountains <- tibble(mountain_name, height_feet, height_meters)
mountains
## # A tibble: 5 × 3
## mountain_name height_feet height_meters
## <chr> <dbl> <dbl>
## 1 Mount Everest 29029 8848
## 2 K2 28251 8611
## 3 Kangchenjunga 28169 8586
## 4 Lhotse 27940 8516
## 5 Makalu 27838 8485
3. What is the mean height of the mountains in feet?
mean(mountains$height_feet)
## [1] 28245.4
4. When were each of these mountains first climbed (i.e. in
what year)? Make a new vector first_climbed and add it to
the mountains data frame.
first_climbed <- c(1953, 1954, 1955, 1956, 1955)
mountains$first_climbed <- first_climbed
mountains
## # A tibble: 5 × 4
## mountain_name height_feet height_meters first_climbed
## <chr> <dbl> <dbl> <dbl>
## 1 Mount Everest 29029 8848 1953
## 2 K2 28251 8611 1954
## 3 Kangchenjunga 28169 8586 1955
## 4 Lhotse 27940 8516 1956
## 5 Makalu 27838 8485 1955
5. How many times have each of these mountains been climbed?
Make a new vector summits and add it to the
mountains data frame.
summits <- c(12884, 800, 532, 933, 499)
mountains$summits <- summits
mountains
## # A tibble: 5 × 5
## mountain_name height_feet height_meters first_climbed summits
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Mount Everest 29029 8848 1953 12884
## 2 K2 28251 8611 1954 800
## 3 Kangchenjunga 28169 8586 1955 532
## 4 Lhotse 27940 8516 1956 933
## 5 Makalu 27838 8485 1955 499
6. Which mountain has the highest number of fatalities? Make
a new vector fatalities and add it to the
mountains data frame.
fatalities <- c(340, 96, 52, 20, 72)
mountains$fatalities <- fatalities
mountains
## # A tibble: 5 × 6
## mountain_name height_feet height_meters first_climbed summits fatalities
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Mount Everest 29029 8848 1953 12884 340
## 2 K2 28251 8611 1954 800 96
## 3 Kangchenjunga 28169 8586 1955 532 52
## 4 Lhotse 27940 8516 1956 933 20
## 5 Makalu 27838 8485 1955 499 72
7. What is the fatality rate (i.e., fatalities divided by
summits) for each mountain? Create a new vector
fatality_rate and add it to the mountains data
frame.
fatality_rate <- mountains$fatalities / mountains$summits
mountains$fatality_rate <- fatality_rate
mountains
## # A tibble: 5 × 7
## mountain_name height_feet height_meters first_climbed summits fatalities
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Mount Everest 29029 8848 1953 12884 340
## 2 K2 28251 8611 1954 800 96
## 3 Kangchenjunga 28169 8586 1955 532 52
## 4 Lhotse 27940 8516 1956 933 20
## 5 Makalu 27838 8485 1955 499 72
## # ℹ 1 more variable: fatality_rate <dbl>
8. Write your data frame to a .csv file called
mountains_data.
write.csv(mountains, "mountains_data.csv", row.names = FALSE)
9. Clear your environment panel by cliking on the broom icon.
Then read in your mountains_data.csv file to a new object
called mountains.
rm(list = ls())
mountains <- read_csv("mountains_data.csv")
## Rows: 5 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): mountain_name
## dbl (6): height_feet, height_meters, first_climbed, summits, fatalities, fat...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
10. Use a summary function of your choice to show the
structure of your mountains data frame.
summary(mountains)
## mountain_name height_feet height_meters first_climbed
## Length:5 Min. :27838 Min. :8485 Min. :1953
## Class :character 1st Qu.:27940 1st Qu.:8516 1st Qu.:1954
## Mode :character Median :28169 Median :8586 Median :1955
## Mean :28245 Mean :8609 Mean :1955
## 3rd Qu.:28251 3rd Qu.:8611 3rd Qu.:1955
## Max. :29029 Max. :8848 Max. :1956
## summits fatalities fatality_rate
## Min. : 499 Min. : 20 Min. :0.02144
## 1st Qu.: 532 1st Qu.: 52 1st Qu.:0.02639
## Median : 800 Median : 72 Median :0.09774
## Mean : 3130 Mean :116 Mean :0.08197
## 3rd Qu.: 933 3rd Qu.: 96 3rd Qu.:0.12000
## Max. :12884 Max. :340 Max. :0.14429
Please knit your work as an .html file and upload to Canvas. Homework is due before the start of the next lab. No late work is accepted. Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!