Introduction

For this assignment, I selected the Online Retail dataset from the UCI Machine Learning Repository. The dataset contains transaction information from a UK-based online retailer and includes information such as products purchased, quantities, prices, customers, transaction dates, and countries. I chose this dataset because I am interested in understanding how retail transaction data can be organized and prepared for future analysis.

Dataset: UCI Machine Learning Repository – Online Retail https://archive.ics.uci.edu/dataset/352/online+retail

Planned Approach

I intend to enter the dataset of Online Retail in R and create a data frame that contains fewer, but more useful variables. The dataset will include variables like invoice number, product description, amount of product sold, invoice date, unit price, customer ID, and country. Additionally, I will be changing the names of the columns to make the variable names easier to understand.

Anticipated Data Challenges

One of the potential problems facing me will be that some of the transactions will have missing customer data or incomplete information about the products. The data set will also contain transactions such as returns and cancellations, which might impact the analysis. The primary aim of my work is to carry out the loading of the data and make a clean subset of it while also recording problems in the process.

Loading and Transforming the Data

The Online Retail dataset is loaded from my public GitHub repository so that the analysis can be reproduced without relying on a local file.

library(readxl)

url <- "https://github.com/LBoodram26/Data607-Week1/raw/refs/heads/main/Online%20Retail.xlsx"

download.file(url, "Online_Retail.xlsx", mode = "wb")

retail <- read_excel("Online_Retail.xlsx")

head(retail)
## # A tibble: 6 × 8
##   InvoiceNo StockCode Description         Quantity InvoiceDate         UnitPrice
##   <chr>     <chr>     <chr>                  <dbl> <dttm>                  <dbl>
## 1 536365    85123A    WHITE HANGING HEAR…        6 2010-12-01 08:26:00      2.55
## 2 536365    71053     WHITE METAL LANTERN        6 2010-12-01 08:26:00      3.39
## 3 536365    84406B    CREAM CUPID HEARTS…        8 2010-12-01 08:26:00      2.75
## 4 536365    84029G    KNITTED UNION FLAG…        6 2010-12-01 08:26:00      3.39
## 5 536365    84029E    RED WOOLLY HOTTIE …        6 2010-12-01 08:26:00      3.39
## 6 536365    22752     SET 7 BABUSHKA NES…        2 2010-12-01 08:26:00      7.65
## # ℹ 2 more variables: CustomerID <dbl>, Country <chr>

Creating a Data Subset

For this analysis, I selected variables that are useful for understanding individual retail transactions. The selected variables contain information about the invoice, product, quantity purchased, transaction date, price, customer, and country.

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
retail_subset <- retail %>%
  select(InvoiceNo, Description, Quantity, InvoiceDate,
         UnitPrice, CustomerID, Country) %>%
  rename(
    invoice_number = InvoiceNo,
    product_description = Description,
    quantity = Quantity,
    invoice_date = InvoiceDate,
    unit_price = UnitPrice,
    customer_id = CustomerID,
    country = Country 
    )
head(retail_subset)
## # A tibble: 6 × 7
##   invoice_number product_description     quantity invoice_date        unit_price
##   <chr>          <chr>                      <dbl> <dttm>                   <dbl>
## 1 536365         WHITE HANGING HEART T-…        6 2010-12-01 08:26:00       2.55
## 2 536365         WHITE METAL LANTERN            6 2010-12-01 08:26:00       3.39
## 3 536365         CREAM CUPID HEARTS COA…        8 2010-12-01 08:26:00       2.75
## 4 536365         KNITTED UNION FLAG HOT…        6 2010-12-01 08:26:00       3.39
## 5 536365         RED WOOLLY HOTTIE WHIT…        6 2010-12-01 08:26:00       3.39
## 6 536365         SET 7 BABUSHKA NESTING…        2 2010-12-01 08:26:00       7.65
## # ℹ 2 more variables: customer_id <dbl>, country <chr>

Creating a Transaction Total

To make the dataset more useful for future sales analysis, I created a new variable called total_price. This variable represents the total value of each transaction line and is calculated by multiplying the quantity purchased by the unit price.

retail_subset <- retail_subset %>%
  mutate(total_price = quantity * unit_price)

head(retail_subset)
## # A tibble: 6 × 8
##   invoice_number product_description     quantity invoice_date        unit_price
##   <chr>          <chr>                      <dbl> <dttm>                   <dbl>
## 1 536365         WHITE HANGING HEART T-…        6 2010-12-01 08:26:00       2.55
## 2 536365         WHITE METAL LANTERN            6 2010-12-01 08:26:00       3.39
## 3 536365         CREAM CUPID HEARTS COA…        8 2010-12-01 08:26:00       2.75
## 4 536365         KNITTED UNION FLAG HOT…        6 2010-12-01 08:26:00       3.39
## 5 536365         RED WOOLLY HOTTIE WHIT…        6 2010-12-01 08:26:00       3.39
## 6 536365         SET 7 BABUSHKA NESTING…        2 2010-12-01 08:26:00       7.65
## # ℹ 3 more variables: customer_id <dbl>, country <chr>, total_price <dbl>

Conclusions and Recommendations

The Online Retail data was loaded into R successfully, and a smaller version of the original data consisting of relevant variables for the analysis of retail transactions was created. I also renamed the chosen variables to make them clearer and calculated the total amount by multiplying the amount of items purchased with the cost per unit.

This data can be further utilized to analyze the sales by country, look into popular products, and to create purchasing behavior among customers. Before doing the analysis, I will also check the missing customer data and canceled or returned purchases.