Resources for Lab 4

Practice 1

  • Download the ecommerce.xlsx file and move it in the project folder. If you open it in Excel, you’ll see it is made of two sheets, named “purchases_history” and “products”.

  • You will need to import both sheets in R.

For importing, use the read_xlsx()function and specify the sheet argument.

# declare where you are in your project folder
i_am("practice1.R")

# construct the path to your data
path <- here("data", "ecommerce.xlsx")

# read the two sheets by specifying the "sheet" argument
purchases <- read_xlsx(path = path, sheet = "purchases_history")
products  <- read_xlsx(path = path, sheet = "products")
  • Clean the names of the two data frames by usign clean_names()from the janitor package.
  • Compute the number of sales by product

Compute the total amount of sales by product in thousands of euros.

Practice 2

  • Download the avocados.xlsx file and move it in your project folder.

  • The dataset contains the average prices ($) of conventional and organic avocados, collected from 2015-01-04 to 2018-03-25.

Transform the data to match

# A tibble: 338 × 3
   date       type         avg_price
   <date>     <chr>            <dbl>
 1 2015-01-04 conventional     1.01 
 2 2015-01-04 organic          1.59 
 3 2015-01-11 conventional     1.11 
 4 2015-01-11 organic          1.63 
 5 2015-01-18 conventional     1.13 
 6 2015-01-18 organic          1.65 
 7 2015-01-25 conventional     1.12 
 8 2015-01-25 organic          1.68 
 9 2015-02-01 conventional     0.962
10 2015-02-01 organic          1.53 
# ℹ 328 more rows

and then use ggplot and geom_line() to plot the average price trajectory across the years by type of avocado

Practice 3

Organise the answers to Lab 3 - Practice 1 in a R markdown file.