Assignment 4

Author

DaQuan

Download and open the assign04.qmd file and complete the exercises.

We will be using pay-per-click (PPC) data from a 31 day campaign from a company that sells USB keys and USB hubs. Each row of the 555 observations represents a click on an internet ad based on a keyword search and there are 3 columns.

In this assignment you will be examining each column for data validity. Each exercise presents one or more questions for you to answer.

We’ll start by loading the tidyverse family of packages along with the janitor and skimr packages, and our data. Make sure you install these two packages in your RStudio prior to calling the library() functions below.

library(tidyverse)
library(janitor)
Warning: package 'janitor' was built under R version 4.4.3
library(skimr)
Warning: package 'skimr' was built under R version 4.4.3
ppc_data <- read_csv("https://jsuleiman.com/datasets/ppc_data.csv")
view(ppc_data)

Exercises

There are six exercises in this assignment. The Grading Rubric is available at the end of this document.

Exercise 1

Create a graph of number of clicks (i.e., observations) for each day (1-31). Use geom_bar() for your geometry. In the narrative below your code note which days had zero clicks.

library(ggplot2)
ppc_data |>
  ggplot(aes(x = day)) + 
  geom_bar(stat = "count") +
labs(title = "Number of Clicks per Day", x = "Day of the Month", y = "Number of Clicks") +
  theme_minimal()

Day 27 Had 0 clicks

Exercise 2

Insert a code cell to show how many NA (i.e., missing) values there are in price. In the narrative below that code cell write out how many NA values there are for price and what percent of the observations that represents.

ppc_data |>
select(price) |>
  filter(is.na(price)) 
# A tibble: 6 × 1
  price
  <dbl>
1    NA
2    NA
3    NA
4    NA
5    NA
6    NA

There are 6 NA values under price, and with there being 555 observations that would mean that it comes out to about 1.08% 6/555 = 0.01081 and then multiply by 100 to get 1.08%

Exercise 3

Valid values for price are 0.1 or greater. Insert a code cell that displays the number of values of price that are less than 0.1. In the narrative below that code cell write how many values are below 0.1.

ppc_data |>
select(price) |>
  filter(price < 0.1) 
# A tibble: 10 × 1
   price
   <dbl>
 1     0
 2     0
 3     0
 4     0
 5     0
 6     0
 7     0
 8     0
 9     0
10     0

Exercise 4

Insert a code cell that drops all of the rows that contain invalid or NA values for price.

ppc_data |>
select(price) |>
  filter(is.na(price)) 
# A tibble: 6 × 1
  price
  <dbl>
1    NA
2    NA
3    NA
4    NA
5    NA
6    NA

Exercise 5

Insert a code cell that shows a tabyl of the counts of each keyword. In the narrative below the code cell, list the misspellings and counts if there are any.

keyword_counts <- ppc_data |>
  tabyl(keyword)
glimpse(keyword_counts)
Rows: 7
Columns: 3
$ keyword <chr> "hub", "key", "ubs", "ubs key", "usb", "usb hub", "usb key"
$ n       <int> 90, 85, 11, 10, 75, 121, 163
$ percent <dbl> 0.16216216, 0.15315315, 0.01981982, 0.01801802, 0.13513514, 0.…

ubs instead of usb 11 times

ubs key instead of usb key 10 times

Exercise 6

Insert a code cell that corrects all the misspellings for keyword, then rerun tabyl to verify.

ppc_data |>
  mutate(keyword = recode(keyword, "ubs" = "usb", "ubs key" = "usb key")) |>
tabyl(keyword) 
 keyword   n   percent
     hub  90 0.1621622
     key  85 0.1531532
     usb  86 0.1549550
 usb hub 121 0.2180180
 usb key 173 0.3117117

Submission

To submit your assignment:

  • Change the author name to your name in the YAML portion at the top of this document
  • Render your document to html and publish it to RPubs.
  • Submit the link to your Rpubs document in the Brightspace comments section for this assignment.
  • Click on the “Add a File” button and upload your .qmd file for this assignment to Brightspace.

Grading Rubric

Item
(percent overall)
100% - flawless 67% - minor issues 33% - moderate issues 0% - major issues or not attempted
Narrative: typos and grammatical errors
(7%)
Document formatting: correctly implemented instructions
(7%)

Exercises

(13% each)

Submitted properly to Brightspace

(8%)

NA NA You must submit according to instructions to receive any credit for this portion.