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.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── 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 errors1. Objects in R are a way in which we can store data or
operations. Make a new object pi as 3.14159. You should now
see the object pi in the environment window in the top
right.
pi <- 3.141592. Write a code chunk that divides pi by 2. Use
the help command ? to learn how to use the
round function to limit your result to 3 significant
digits.
?round
round(pi/2, digits=3)## [1] 1.5713. Calculate the mean for the numbers 2, 8, 4, 6, 7, 4, 9, 9,
10. Please start by making a new object x that holds these
values then use mean to perform the
calculation.
x <- c(2, 8, 4, 6, 7, 4, 9, 9, 10)mean(x)## [1] 6.5555564. 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)5. 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          84856. What is the mean height of the mountains in feet?
mean(mountains$height_feet)## [1] 28245.47. 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          19558. 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     4999. 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         7210. Write your data frame to a .csv file.
write.csv(mountains, "mountains_data.csv", row.names = FALSE)Please knit your work as a .pdf or .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!