MarcelaRobinson_challenge4

Author

Marcela Robinson

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0     ✔ purrr   1.0.1
✔ tibble  3.1.8     ✔ dplyr   1.1.0
✔ tidyr   1.3.0     ✔ stringr 1.5.0
✔ readr   2.1.3     ✔ forcats 1.0.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(lubridate)

Attaching package: 'lubridate'

The following objects are masked from 'package:base':

    date, intersect, setdiff, union
library(stringr)

##Read in data

poultry<-read_csv("_data/poultry_tidy.csv")
Rows: 600 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): Product, Month
dbl (2): Year, Price_Dollar

ℹ 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.
head(poultry)

The dataset poultry contains information related to the price per month of poultry cuts from 2004 - 2013. The dataset contains 600 observations and 4 different variables. The variables for this dataset are: -Product: This variable contains different poultry cuts including whole, breast, boneless breast, bone-in breast, whole legs, and thighs. -Year and month: These variables contain the month and the year for each poultry cut price. Price_dollar: The dollar amount per month for each poultry cut.

The first step I want to do to clean the data is to combine the month and the year to reduce the number of columns. Next, I would like to use the mutate_if function to have 2 decimals for the price of the cuts.

##Combine year and month to reduce number of columns

poultry_date<-poultry%>%
  mutate(date = str_c(Month, Year, sep=" "),
         date = my(date))%>%
  select(Product, Price_Dollar,date)

head(poultry_date)

##Move decimal place

poultry_date%>%
  mutate_if(is.numeric, ~round(., 2))