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)
<- read_csv("~/project/Markdown_Training/Homework/data/worldcup_top.csv") worldcup_top
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()
<- read_delim("~/project/Markdown_Training/Homework/data/worldcup_bottom.csv",delim = "|",
worldcup_bottom 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 %>%
worldcup_top_piped select(year,goals_scored)
#selecting some columns from worldcup_bottom_df
<- worldcup_bottom%>%
worldcup_bottom_piped 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
<- data.frame(
stock_data 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)
)
<- data.frame(
staff_data 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)
)
<- list(
shop_1_list active = TRUE,
stock = stock_data,
staff = staff_data
)
<- list(
shop_2_list active = FALSE,
stock = stock_data,
staff = staff_data
)
<- list(
shops_list shop_1 = shop_1_list,
shop_2 = shop_2_list
)
# Answer the questions here:
# (a)
2]] shop_1_list[[
## 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)
$staff[1] shop_1_list
## names
## 1 Jean de Dieu
## 2 Martha