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.
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
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(tidyverse)library(janitor)library(skimr)library(ggplot2)ggplot(ppc_data, aes(x =factor(day), y= price)) +geom_bar(stat ="identity", fill ="steelblue")
Warning: Removed 6 rows containing missing values or values outside the scale range
(`geom_bar()`).
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.
library(skimr) ppc_data |>skim()
Data summary
Name
ppc_data
Number of rows
555
Number of columns
3
_______________________
Column type frequency:
character
1
numeric
2
________________________
Group variables
None
Variable type: character
skim_variable
n_missing
complete_rate
min
max
empty
n_unique
whitespace
keyword
0
1
3
7
0
7
0
Variable type: numeric
skim_variable
n_missing
complete_rate
mean
sd
p0
p25
p50
p75
p100
hist
day
0
1.00
16.41
8.34
2
9.0
17.0
23.0
31
▆▇▇▇▆
price
6
0.99
4.74
2.92
0
2.2
4.7
7.3
10
▇▇▇▆▆
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.
# Count how many price values are less than 0.1ppc_data %>%filter(price <0.1) %>%summarise(count =n())
# A tibble: 1 × 1
count
<int>
1 10
10 values are below 0.1.
Exercise 4
Insert a code cell that drops all of the rows that contain invalid or NA values for price.
ppc_data |>filter(!is.na(price))
# A tibble: 549 × 3
day keyword price
<dbl> <chr> <dbl>
1 9 usb 5.9
2 30 usb hub 8
3 19 usb hub 2.8
4 4 usb key 7.7
5 30 key 1.7
6 17 usb hub 5.5
7 5 hub 5.2
8 8 key 3.8
9 17 usb key 6
10 21 usb key 2
# ℹ 539 more rows
6 rows contain invalid or “NA” values for price!
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.
ppc_data |>tabyl(keyword)
keyword n percent
hub 90 0.16216216
key 85 0.15315315
ubs 11 0.01981982
ubs key 10 0.01801802
usb 75 0.13513514
usb hub 121 0.21801802
usb key 163 0.29369369
Misspellings: There are 11 ubs, and 10 ubs key.
Exercise 6
Insert a code cell that corrects all the misspellings for keyword, then rerun tabyl to verify.