Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve the below in RStudio title: Problem Set #1 - `dplyr` basics subtitle: Data Wrangling with `dplyr` author: your name date: `r Sys.Date()` output:

Please solve the below in RStudio

title: "Problem Set #1 - `dplyr` basics" subtitle: Data Wrangling with `dplyr` author: "your name" date: "`r Sys.Date()`" output: html_document: default ---

```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE) library(tidyverse)

```

## Directions

During ANLY 512 we will be studying the theory and practice of *data visualization*. We will be using `R` and the packages within `R` to assemble data and construct many different types of visualizations. Before we begin studying data visualizations we need to develop some data wrangling skills. We will use these skills to wrangle our data into a form that we can use for visualizations.

The objective of this assignment is to introduce you to R Studio, Rmarkdown, the tidyverse and more specifically the `dplyr` package.

Each question is worth 5 points.

To submit this homework you will create the document in Rstudio, using the knitr package (button included in Rstudio) and then submit the document to your [Rpubs](http://rpubs.com/) account. Once uploaded you will submit the link to that document on Canvas. Please make sure that this link is hyper linked and that I can see the visualization and the code required to create it.

Question #1

Use the nycflights13 package and the flights data frame to answer the following questions: a.What month had the highest proportion of cancelled flights? b.What month had the lowest?

```{r #1} library(nycflights13)

```

Question #2

Consider the following pipeline:

```{r #2, eval=FALSE}

library(tidyverse) mtcars %>% group_by(cyl) %>% summarize(avg_mpg = mean(mpg)) %>% filter(am == 1)

```

What is the problem with this pipeline?

Question #3

Define two new variables in the `Teams` data frame in the `pkg Lahman()` package.

a. batting average (BA). Batting average is the ratio of hits (H) to at-bats (AB)

b. slugging percentage (SLG). Slugging percentage is total bases divided by at-bats (AB). To compute total bases, you get 1 for a single, 2 for a double, 3 for a triple, and 4 for a home run.

```{r #3} library(Lahman)

```

Question #4

Using the `Teams` data frame in the `pkg Lahman()` package. display the top-5 teams ranked in terms of slugging percentage (SLG) in Major League Baseball history. Repeat this using teams since 1969. Slugging percentage is total bases divided by at-bats.To compute total bases, you get 1 for a single, 2 for a double, 3 for a triple, and 4 for a home run.

```{r #4} library(Lahman)

```

Question #5

Use the `Batting`, `Pitching`, and `People` tables in the `pkg Lahman()` package to answer the following questions.

a.Name every player in baseball history who has accumulated at least 300 home runs (HR) and at least 300 stolen bases (SB). You can find the first and last name of the player in the Master data frame. Join this to your result along with the total home runs and total bases stolen for each of these elite players.

a. Similarly, name every pitcher in baseball history who has accumulated at least 300 wins (W) and at least 3,000 strikeouts (SO).

b. Identify the name and year of every player who has hit at least 50 home runs in a single season. Which player had the lowest batting average in that season?

```{r #5} library(Lahman)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Optimization And Data Science Trends And Applications 5th Airoyoung Workshop And Airo Phd School 2021 Joint Event

Authors: Adriano Masone ,Veronica Dal Sasso ,Valentina Morandi

1st Edition

3030862887, 978-3030862886

More Books

Students also viewed these Databases questions