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.
day - represents the day of the campaign. Valid days are 1-31.
price - represents the price of the campaign. Price can’t be a number below 0.10
keyword - represents the keyword purchased. Everything must be spelled correctly, there aren’t many keywords but they are some combination of “usb” and/or “key” or “hub”
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.
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.
clicks_per_day <- ppc_data %>%count(day) %>%ggplot(aes(x =factor(day), y = n)) +geom_bar(stat ="identity") +labs(title ="Number of Clicks per Day",x ="Day",y ="Number of Clicks")clicks_per_day
Narrative: The only two days that had zero clicks were days 1 and 27. ### 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.
# A tibble: 2 × 3
`is.na(price)` n percent
<lgl> <int> <dbl>
1 FALSE 549 98.9
2 TRUE 6 1.08
Narrative: Out of 555 observations there are 6 missing values for price which represents 1.08% of the observations.
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 %>%count(price <0.1)
# A tibble: 3 × 2
`price < 0.1` n
<lgl> <int>
1 FALSE 539
2 TRUE 10
3 NA 6
Narrative: There are 10 values of price that are less than 0.1. However, there are 6 missing values for price which are also invalid. So there are 16 invalid values for price, 10 being less than 0.1 and 6 being missing values.
Exercise 4
Insert a code cell that drops all of the rows that contain invalid or NA values for price.
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.
ppc_data %>%tabyl(keyword) %>%arrange(desc(n))
keyword n percent
usb key 163 0.29369369
usb hub 121 0.21801802
hub 90 0.16216216
key 85 0.15315315
usb 75 0.13513514
ubs 11 0.01981982
ubs key 10 0.01801802
There are two misspellings for keyword in the dataset. The first is “ubs” meant to be “usb” and there is 11 counts of this mistake. Along with this “ubs key” is another misspelling meant to be “usb key” and there are 10 counts of this mistake.
Exercise 6
Insert a code cell that corrects all the misspellings for keyword, then rerun tabyl to verify.