The purpose of this assignment is to allow you to practically implement the concepts introduced during class. Although some of the content builds on the class discussion and examples, the exercises go beyond the scope of only the material covered in class. You are encouraged to consult external sources to solve the challenges in this document.
What are the shortcut commands for the following:
<-)%>%)ANSWER 1
worldcup_top.library(tidyverse)
worldcup_top <- read_csv("~/project/Markdown_Training/Homework/data/worldcup_top.csv")worldcup_bottom. Why do we need to take a different
approach than we did in (a)?#worldcup_bottom <- rio::import("~/project/Markdown_Training/Homework/data/worldcup_bottom.csv") %>% janitor::clean_names()
worldcup_bottom <- read_delim("~/project/Markdown_Training/Homework/data/worldcup_bottom.csv",delim = "|",
show_col_types = FALSE)
colnames(worldcup_bottom) <- gsub("(.*)[0-9]+?_", "", colnames(worldcup_bottom))year and
goals_scored column from worldcup_top and
worldcup_bottom respectively. What is different about
worldcup_bottom, how do you address this issue?#selecting some columns from worldcup_top df
worldcup_top_piped <- worldcup_top %>%
select(year,goals_scored)
#selecting some columns from worldcup_bottom_df
worldcup_bottom_piped <- worldcup_bottom%>%
select(year,goals_scored)The difference between df are follow: (a) worldcup_top is like head of data set which is starting from year \(1930\) and other is like tail of the entire data which is started from \(1982\).
The code chunk below creates a list called shops_list
that you also saw in the class material. Extract from the list using
only [] and [[]] indexing:
# code to create shops_list
stock_data <- data.frame(
crops = c("maize", "soya", "rice", "potatoes"),
quantity_ordered = c(100, 200, 38, 1050),
price_per_kg = c(1000, 1855.99, 99.50, 500),
in_stock = c(TRUE, TRUE, FALSE, TRUE)
)
staff_data <- data.frame(
names = c("Jean de Dieu", "Martha"),
monday = c(TRUE, TRUE),
tuesday = c(TRUE, TRUE),
wednesday = c(FALSE, TRUE),
thursday = c(FALSE, TRUE),
friday = c(TRUE, TRUE)
)
shop_1_list <- list(
active = TRUE,
stock = stock_data,
staff = staff_data
)
shop_2_list <- list(
active = FALSE,
stock = stock_data,
staff = staff_data
)
shops_list <- list(
shop_1 = shop_1_list,
shop_2 = shop_2_list
)
# Answer the questions here:
# (a)
shop_1_list[[2]]## crops quantity_ordered price_per_kg in_stock
## 1 maize 100 1000.00 TRUE
## 2 soya 200 1855.99 TRUE
## 3 rice 38 99.50 FALSE
## 4 potatoes 1050 500.00 TRUE
# (b)
shop_1_list$staff[1]## names
## 1 Jean de Dieu
## 2 Martha