Code
library(tidyverse)
library(readxl)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Lai Wei
November 9, 2022
Today’s challenge is to:
Read in one (or more) of the following datasets, using the correct R package and command.
Error: 'D:/Umass Amherst/DACSS 601/601_Fall_2022/posts/_data/eggs_tidy.csv' does not exist.
Error in eval(expr, envir, enclos): object 'Fed' not found
Using colnames() function to see each colnames’ catagory.
They look good enough to be understood. I will leave them like that.
Using mutate() function to create a new colname showing the total amount of dozen in each month.
Error in mutate(Fed, total = large_half_dozen + large_dozen + extra_large_half_dozen + : object 'Fed' not found
Error in eval(expr, envir, enclos): object 'Fed_total' not found
Using summarise function to calculate the total number of each year.
---
title: "Challenge 4"
author: "Lai Wei"
desription: "More data wrangling: pivoting"
date: "11/09/2022"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- challenge_4
- abc_poll
- eggs
- fed_rates
- hotel_bookings
- debt
---
```{r}
#| label: setup
#| warning: false
#| message: false
library(tidyverse)
library(readxl)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
## Challenge Overview
Today's challenge is to:
1) read in a data set, and describe the data set using both words and any supporting information (e.g., tables, etc)
2) tidy data (as needed, including sanity checks)
3) identify variables that need to be mutated
4) mutate variables and sanity check all mutations
## Read in data
Read in one (or more) of the following datasets, using the correct R package and command.
- abc_poll.csv ⭐
- poultry_tidy.xlsx or organiceggpoultry.xls⭐⭐
- FedFundsRate.csv⭐⭐⭐
- hotel_bookings.csv⭐⭐⭐⭐
- debt_in_trillions.xlsx ⭐⭐⭐⭐⭐
```{r}
Fed <- read_csv("D:/Umass Amherst/DACSS 601/601_Fall_2022/posts/_data/eggs_tidy.csv")
Fed
```
### Briefly describe the data
## Tidy Data (as needed)
Using colnames() function to see each colnames' catagory.
```{r}
Fed %>%
colnames()
```
They look good enough to be understood. I will leave them like that.
## Identify variables that need to be mutated
Using mutate() function to create a new colname showing the total amount of dozen in each month.
```{r}
Fed_total <- mutate(Fed, total = large_half_dozen + large_dozen + extra_large_half_dozen + extra_large_dozen)
Fed_total
```
Using summarise function to calculate the total number of each year.
```{r}
group_by(Fed_total,year) %>%
summarise(Total = sum(total))
```