Data Analysis and Visualization - Midterm - Student answers

Author

alper yilmaz

Published

June 17, 2023

Unfortunately, you cannot see your answers at online.yildiz.edu.tr address. So this page shows your answers.

ogrenci_numarasi question_no verilen_cevap
17056010 Q1

No we cant determine how heavy the heaviest tennis player in the 2020 olympics is because data base ve use in this question does not have the data for 2020 olympics.İf we change our database or we import necesseriy datas for this question we can solve it using r language.

17056010 Q11

#İmporting our data
olympics <- read.table(“https://zenodo.org/record/6803028/files/olympics.tsv”, header = TRUE, sep = “\t”)#We find height column and the tallest athlete datatallest_athlete <- olympics[which.max(olympics$Height),]#We print the name and height of the tallest athletecat(“The tallest athlete competing in the Olympic games was”, tallest_athlete$Name, “from”, tallest_athlete$NOC, “with a height of”, tallest_athlete$Height, “cm.”)The tallest competing athlete is Zhaoxu Zhang from China, with a height of 223 cm.

17056010 Q2

#İmporting our dataolympics <- read.table(“https://zenodo.org/record/6803028/files/olympics.tsv”, header = TRUE, sep = “\t”)#Filtering the data for most recent olympicsrecent_summer_olympics <- subset(olympics, Year == max(olympics$Year) & Season == “Summer”)# Find the lightest athlete using the “Weight” columnlightest_athlete <- recent_summer_olympics[which.min(recent_summer_olympics$Weight),]# Then we print the name and weight of athletecat(“The lightest athlete of the most recent Summer Olympics is”, lightest_athlete$Name, “from”, lightest_athlete$NOC, “with a weight of”, lightest_athlete$Weight, “kg.”)The lightest athlete of the most recent summer olympics is Nurislam Sanayev from Kaz with a weight of 48 kg.

17056010 Q6

First we import the datadata < - read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv”,”, header = TRUE, sep = “\t”)İn gold medals section we find the sum of ittotal_gold_medals <- sum(olympics$Gold)We print the resultcat(“The total number of gold medals handed out in all games is:”, total_gold_medals)The total number of gold medals handed out in all games is: 10484

17056033 Q1

library(dplyr)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")max_weight <- max(olympics$Weight, na.rm = TRUE)most_heavy_person <- olympics[olympics$Weight == max_weight, ]

17056033 Q13

olympics <- read.csv(“https://zenodo.org/record/6803028/files/olympics.tsv”, sep = “\t”)last_alphabetically <- olympics %>%
filter(Season == “Summer” & Year == max(Year[Season == “Summer”])) %>%
arrange(desc(strsplit(Athlete, “, “)[[1]][2])) %>%
slice(1)last_alphabetically

17056033 Q14

olympics <- read.delim(“https://zenodo.org/record/6803028/files/olympics.tsv”, sep=”\t”)most_participating_country <- olympics %>%

group_by(Team) %>%

summarise(total_participation = n()) %>%

arrange(desc(total_participation)) %>%

slice(1)most_participating_country

17056033 Q2

library(dplyr)library(readr)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")lightest_athlete <- olympics %>%
filter(Season == “Summer” & Year == max(Year[Season == “Summer”])) %>%
arrange(Weight) %>%
slice(1)lightest_athlete

17056033 Q8

olympics <- read.delim(“https://zenodo.org/record/6803028/files/olympics.tsv”, sep = “\t”)medals_2018 <- olympics %>%
filter(Year == 2018) %>%
summarise(total_medals = sum(!is.na(Medal)))medals_2018$total_medals

1705A045 Q11

{r}library(tidyverse)library(dplyr)data <- read_tsv("https://zenodo.org/record/6803028/files/olympics.tsv")data %>%<br>select(name, height) %>%<br>na.omit() %>%<br>arrange(-height) %>%<br>slice(1)
nameheight


Adam Sandurski214


1705A045 Q14

{r}data %>%<br>count(team, sort = TRUE) %>%<br>slice(1)<br>
teamn


United States17286


1705A045 Q16

{r}library(gapminder)``````{r}gapminder %>%<br>select(country, gdpPercap) %>%<br>arrange(-gdpPercap) %>%<br>slice(1)
countrygdpPercap


Kuwait113523.1


1705A045 Q4

{r}library(tidyverse)library(dplyr)data <- read_tsv("https://zenodo.org/record/6803028/files/olympics.tsv")data %>%<br>select(name, height) %>%<br>na.omit() %>%<br>arrange(height) %>%<br>slice(1)
nameheight


Lyton Mphande127


1705A045 Q6

{r}data %>%<br>select(medal) %>%<br>na.omit() %>%<br>filter(medal == "Gold") %>%<br>count(medal, sort = TRUE)
medaln


Gold8110


1705A045 Q9

{r}data %>%<br>select(name,sex, height,sport, medal) %>%<br>na.omit() %>%<br>filter (sex == "F" ,<br><br> <br> <br> <br> <br>sport == "Badminton",<br> <br> <br> <br> <br>medal == "Gold") %>%<br>arrange(height) %>%<br>slice(1)namesexheightsportmedalSusy SusantiF161BadmintonGold

18056004 Q16

Hocam metin olarak ekleyemedim bu şekilde ekleemk zorundayım

18056004 Q2

library(dplyr)
olympics <- read_tsv(“olympics.tsv”)
recent_summer_olympics <- olympics %>% filter(Year == max(Year[!is.na(Year)]) & Season == “Summer”)

lightest_athlete <- recent_summer_olympics[which.min(recent_summer_olympics$Weight),]

cat(“The lightest athlete of the most recent Summer Olympics was”, lightest_athlete$Name, “with a weight of”, lightest_athlete$Weight, “kg.”

I can not because “Unknown or uninitialised column: Light.”

18056004 Q21

Rumeysa Bağgül Data Vize SS.png

18056004 Q7

library(dplyr)
olympics %>% filter(!is.na(Height), Height < 160, Medal == “Gold”, !grepl(“Team”, Sport)) %>%
summarise(num_gold_medals = n())num_gold_medals
31

18056023 Q10

library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%
filter(str_detect(games, “1964”)) %>%
filter(team == “Denmark”) %>%
mutate(avg_height = mean(height)) %>%
relocate(avg_height, .after = name)
answer:
175.913 and whole output:1699Tom Bogs175.913M194421 NovemberKøbenhavn (Copenhagen) (DEN)
1730Børge Krogh175.913M194218 AprilAalborg (DEN)
1755Hans-Erik Pedersen175.913M194310 DecemberVejle (DEN)
1760Preben Rasmussen175.913M194114 NovemberKøbenhavn (Copenhagen) (DEN)
9411Anni Werner-Hansen175.913F193921 JulyVig, Odsherred (DEN)
9412Birthe Lindskov Hansen175.913F19448 JuneHolstebro (DEN)
9412Birthe Lindskov Hansen175.913F19448 JuneHolstebro (DEN)
9433Erik Hansen175.913M193915 NovemberRanders (DEN)
14362Niels Fredborg175.913M194628 OctoberOdder (DEN)
14362Niels Fredborg175.913M194628 OctoberOdder (DEN)

18056023 Q11

library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%
arrange(desc(height))answer:59674Adam Sandurski214M19538 February

18056023 Q12

library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%
count(sport, games) %>%
count(games) %>%
arrange(desc(n))answer:2020 Summer Olympics38

18056023 Q16

{r}library(gapminder)gapminder %>%<br>filter(year == 1987) %>%<br>arrange(desc(gdpPercap))output:NorwayEurope198775.890418614731540.9748

18056023 Q4

library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%
filter(str_detect(games, “Winter Olympics”)) %>%
arrange(height) %>%
relocate(height, .after = name)answer:81564Carolyn Krau137F194318 August

18056023 Q8

library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%
filter(str_detect(games, “2018”)) %>%
filter(!is.na(medal))answer:A tibble:383 × 17 , so the anwer is 383

18056031 Q10

data%>%
filter(noc==“DEN”, games==“1964 Summer Olympics”) %>%
filter(!is.na(height)) %>%
summarise(avg= mean(height))176.0976

18056031 Q15

data %>%arrange(desc(games), desc(height)) %>%
select(name, height, games)
Gennaro Di Mauro2102020 Summer Olympics

18056031 Q19

code.png

18056031 Q2

data%>%

arrange(desc(games)) %>%
mutate(weight=parse_number(weight)) %>%
arrange(weight)%>%
select(name, weight)

Choi Myong-Hui25

18056031 Q5

data%>%
arrange(desc(games)) %>%
count(games, noc)

18056031 Q7

data%>%

filter(medal==“Gold”, height<160)

18056058 Q10

olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")denmark_1964 <- olympics %>% filter(year == 1964 & team == “Denmark”)avg_height <- denmark_1964 %>% summarise(mean_height = mean(height, na.rm = TRUE))avg_height$mean_height

18056058 Q11

olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")athletes <- olympics %>% filter(!is.na(height))tallest_athlete <- athletes %>% slice_max(height)
tallest_athlete %>% select(name, sex, height)

18056058 Q18

library(gapminder)turkey_data <- filter(gapminder, country == “Turkey”)wealthiest_year <- filter(turkey_data, gdpPercap == max(gdpPercap))wealthiest_year# A tibble: 1 x 6
country continent
year lifeExp


pop gdpPercap








1 Turkey
Europe

2013

76.2 75627384

19900.

18056058 Q3

olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")athletes <- olympics %>% filter(!is.na(height))shortest_athlete <- athletes %>% slice_min(height)shortest_athlete %>% select(name, sex, height, year, sport, team, games)
# A tibble: 1 x 7
name





sex
height
year sport

team



games




















1 Rosario Briones F
127
2000 Gymnastics Mexico

2000 Summer

18056058 Q5

olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")last_olympics <- olympics %>% filter(year == 2016)num_countries <- last_olympics %>% distinct(NOC, .keep_all = TRUE) %>% count( )num_countries$n
180.5 cm

18056058 Q6

olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")total_gold_medals <- olympics %>% filter(medal == “Gold”) %>% count()total_gold_medals$n

18056066 Q13

—title: “R Notebook”output: html_notebook—{r}library(tidyverse)## Load File{r}fileurl = "https://zenodo.org/record/6803028/files/olympics.tsv"data = read_tsv(fileurl, show_col_types = FALSE)### Display first 5 observations{r}head(data)``````{r}### display column namescolnames(data)### Q1
{r}# first sort yearsrecent_data <- data %>%<br>arrange(desc(year))head(recent_data)Earliest year is 2020{r}# now find the athlet that comes lastrecent_data <- recent_data %>%<br>filter(year ==2020) %>%<br>arrange(name)tail(recent_data)Answer: “Žolt Peto”

18056066 Q17


{r}library(gapminder)#Q4{r}head(gapminder)``````{r}gapminder %>%<br>arrange(desc(gdpPercap))Answer: Kuwait

18056066 Q2

Q3{r}recent_data %>%<br>arrange(weight)Answer:100

18056066 Q9

Q2:{r}data %>%<br>filter(sport =="Badminton") %>%<br>filter (sex == "F") %>%<br>arrange(height)Answer:150

18056501 Q15

data %>%

filter(games == max(games)) %>%

arrange(height)
Output:
Name: Flávia SaraivaHeight: 133

18056501 Q17

data %>%

filter(continent == “Asia”) %>%
arrange(desc(gdpPercap))
Output:
KuwaitAsia195758.03300212846113523.1329

18056501 Q2

data %>%



filter(max(games)) %>%



arrange(weight)
Output:Jevgēņijs Borodavko

18056501 Q21

Ekran görüntüsü 2023-04-27 121339.png

18056501 Q5

data %>%


filter(games == max(games)) %>%


count(team) %>%


nrow()
Output: 250

18056501 Q6

data %>%

filter(!is.na(medal)) %>%

filter(medal == “Gold”)
Output: 8110

18056501 Q9

data %>%

filter(medal == “Gold”, sport == “Badminton”) %>%

arrange(height)
Output: 161

1805A007 Q1

library(olypics.stv)olympics 2020 ← olympics %>%


filter(Year == 2020)tennis players ← olympics 2020 %>%


filter(Sport == ‘’ Tennis’’)tennis players sorted ← tennis players %>%


arrange(desc(Weight))

1805A007 Q11

library(olympics.stv)tallest athlete ← athlete events %>%


filter(Height) %>%


filter(Height == max(Height))

1805A007 Q14

library(olympics.stv)participations by country ← athlete event %>%


group_by(Team) %>%


summarize(participations)most_participations ← participations by country %>%


filter(participations == max(participations))

1805A007 Q18

library(gapminder)turkey data ← gapminder %>%


filter(country == ‘’Turkey’’wealthiest year ← turkey data %>%


filter(gdpPercap == max(gpdPercap))

1805A007 Q3

library(olympics.stv)athlete heights ← athlete events %>%


filter(Height == min(Height)

1805A007 Q8

library(olympics.stv)medals_2018 ← medals %>%


filter(Year == 2018)


count(medals_2018)

1805A009 Q13

library(olympics)olympics %>%slice_max(year, n=1)arrange(name)

1805A009 Q16

install.packages(“gapminder”)library(gapminder)gapminder %>%group_by(country) %>%filter(year == 1987) %>%summarize(maxGdpPercap = max(gdpPercap))KuwaitAsia195758.033212846113523.1329


1805A009 Q4

library(olympics)olympics %>%group_by(game ==
athletism) %>%filter(season == summer) %>%slice_min(height, n=1)

1805A009 Q5

library(olympics)olympics%>%group_by(country) %>%summarize(total_country= sum(Country)

1805A009 Q6

library(olympics)olympics %>%filter( medal == gold) %>%summarize(total_medal = sum(medal))

1805A009 Q9

library(olympics)olympics %>%filter(game == badminton, sex == woman) %>%group_by(medal == gold) %>%slice_min(height, n=1)

1805A015 Q15

olympics <- read.delim(“https://zenodo.org/record/6803028/files/olympics.tsv")tallest_athlete <- olympics %>%
filter( year == max(year)) %>%
filter((Height)) %>%
arrange(desc(Height)) %>%
select(Name, Height) %>%
slice(1)

1805A015 Q18

library(gapminder)turkey_gdp <- gapminder %>%
filter(country == “Turkey”) %>%
arrange(desc(gdpPercap))wealthiest_year_turkey <- turkey_gdp[1,]wealthiest_year_turkey

country continent
year
lifeExp



pop



gdpPercap












1
Turkey
Europe


2007

71.8

71158647


8458.


1805A015 Q4

olympics <- read.delim(“https://zenodo.org/record/6803028/files/olympics.tsv")winter_olympics <- olympics %>%
filter(season == “Winter”) %>%
shortest_athlete <- winter_olympics %>%
filter((Height)) %>%
arrange(Height) %>%
slice(1)shortest_athlete

1805A015 Q5

olympics <- read.delim(“https://zenodo.org/record/6803028/files/olympics.tsv")num_countries <- olympics %>%
filter(year == max(year)) %>%
distinct(Team, .keep_all = TRUE) %>%
summarize(num_countries = n())
slice(1)num_countries

1805A015 Q8

olympics <- read.delim(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics_2018 <- olympics %>%
group_by(medal) %>%
mutate(number_medals = count(medal) %>%
summarize(total_medals = sum(number_medals))total_medals

1805A015 Q9

olympics <- read.delim(“https://zenodo.org/record/6803028/files/olympics.tsv")winter_olympics <- olympics %>%
filter(season == “Winter”, sex == “Women”, sport == “Badminton”, medal == “Gold”) %>%
shortest_women <- winter_olympics %>%
filter((Height)) %>%
arrange(Height) %>%
slice(1)shortest_women

1805A034 Q11

Add your R code here!library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")tallest_athlete <- olympics %>%filter(!is.na(Height)) %>%arrange(desc(Height)) %>%slice(1) %>%select(Name, Height)cat(“The tallest athlete is”, tallest_athlete$Name, “with a height of”, tallest_athlete$Height, “cm.”)

1805A034 Q14

Add your R code# Load the olympics datalibrary(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")# Count the number of times each country appears in the dataparticipations <- olympics %>%
count(country, name = “participations”)

1805A034 Q16

install.packages(“gapminder”)library(gapminder)library(dplyr)
gapminder %>%
group_by(continent, year) %>%
filter(continent == “Asia”) %>%slice_max(gdpPercap)

1805A034 Q19

library(readr) # Import the file data <- read_delim(“https://raw.githubusercontent.com/alperyilmaz/data/main/import/problematic_file1.txt”, delim = “,”, col_names = FALSE, skip = 2, comment = “#”) # Rename the columns colnames(data) <- c(“ID”, “Final_Grade”) # Calculate the average final grade per student avg_final_grade <- aggregate(Final_Grade ~ ID, data = data, FUN = mean) # Print the result avg_final_grade

1805A034 Q3

Add your R code here# Load the olympics datalibrary(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")# Find the height of the shortest athleteshortest_athlete <- olympics %>%
filter(!is.na(Height)) %>%
arrange(Height) %>%
slice(1) %>%
select(Name, Height)# Print the resultcat(“The shortest athlete is”, shortest_athlete$Name, “with a height of”, shortest_athlete$Height, “cm.”)

1805A034 Q8

Add your R code here# Load the olympics datalibrary(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv?downloaded=1")# Filter for the 2018 Olympics and sum the medalsmedals_2018 <- olympics %>%filter(Year == 2018) %>%summarise(total_medals = sum(Total.Medals))# Print the resultcat(“The total number of medals handed out during the 2018 Olympics was”, medals_2018$total_medals)

1805A034 Q9

data %>%
filter(medal == “Gold”, sport == “Badminton”) %>%
arrange(height)

1805A048 Q1

We can arrange the heavy of the tennis player and we can choose the heaviest player by limiting the row

1805A048 Q3

olympicdata ←read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")%>%







select (weight)%>%







filter(arrange(desc(weight)))














1805A048 Q5

library(tidyverse)lastolympics←lastolympics <- read_csv(“datacam/p- data/tidy-olympics/presentation.html”)%>%




count(countries)%>%





rename(num_countries=n)



1805A051 Q12

Load necessary librarieslibrary(dplyr)# Read in Olympics dataolympics <- read.csv(“olympics.tsv”)# Group data by Year and count number of unique sportssports_by_year <- olympics %>%
group_by(Year) %>%
summarize(num_sports = n_distinct(Sport))# Find Year with most unique sportsmost_sports_index <- which.max(sports_by_year$num_sports)most_sports_year <- sports_by_year[most_sports_index, “Year”]# Print resultscat(paste(“The Olympics with the most different sports was in”, most_sports

1805A051 Q15


Load necessary librarieslibrary(dplyr)# Read in Olympics dataolympics <- read.csv(“olympics.tsv”)# Filter data to include only Tokyo 2020 athletestokyo_2020 <- olympics %>%
filter(Year == 2021 & Season == “Summer”)# Find tallest athletetallest_index <- which.max(tokyo_2020$Height)tallest_name <- olympics[tallest_index, “Name”]tallest_height <- olympics[tallest_index, “Height”]# Print resultscat(paste(“The tallest athlete from the Olympics was”, tallest_name, “at a height of”, tallest_height, “cm.”))

1805A051 Q8

Load necessary librarieslibrary(dplyr)# Read in Olympics dataolympics <- read.csv(“olympics.tsv”)# Filter data to include only 2018 Winter Olympics eventsAmadel <- olympics %>%# Count number of medals handed outmedal_count <- sum(Amadel$Gold, Amadel$Silver, Amadel$Bronze)# Print resultscat(paste(“A total of”, medal_count, “medals Olympics.”))

19056008 Q15

The Code# Load Datasetwd(“C:\Users\adnan\Downloads\olympics.tsv”)# Read in the olympics.tsv file using read.table() functionolympics_data <- read.table(“olympics.tsv”, sep=”\t”, header=TRUE)# Filter the data to include only athletes from the most recent Olympicsrecent_olympics_data <- olympics_data[olympics_data$Year == 2020,]# Find the row with the tallest athletetallest_athlete_row <- which.max(recent_olympics_data$Height)# Extract the name and height of the tallest athletetallest_athlete_name <- recent_olympics_data$Name[tallest_athlete_row]tallest_athlete_height <- recent_olympics_data$Height[tallest_athlete_row]# Print the resultcat(“The tallest athlete from the most recent Olympics was”, tallest_athlete_name, “who was”, tallest_athlete_height, “cm tall.”)

19056008 Q17

The Code# Load gapminder librarylibrary(gapminder)# Filter for Asia continentasia_data <- gapminder %>% filter(continent == “Asia”)# Find row with highest gdpPercapwealthiest_country <- asia_data[which.max(asia_data$gdpPercap),]# Print resultwealthiest_country
The Result
country

continent
year
lifeExp

pop gdpPercap










1 Kuwait


Asia


1957

58.0 2128465
113523

19056008 Q6

The Code# Set the working directory to the location where your .tsv file is savedsetwd(“C:\Users\adnan\Downloads\olympics.tsv”)
# Read in the olympics.tsv file using read.table() functionolympics_data <- read.table(“olympics.tsv”, sep=”\t”, header=TRUE)
# Use the sum() function to calculate the total number of gold medalstotal_gold_medals <- sum(olympics_data$Gold)
# Print the resultcat(“The total number of gold medals handed out in all games is”, total_gold_medals)

19056011 Q11

library(tidyverse)data ← read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%

arrange(desc(height)) %>%

select(name, height) %>%

slice(1L)Answer from Posit Cloud :Adam Sandurski2.14


19056011 Q12

library(tidyverse)data ← read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%

count(games, sport) %>%

count(games, sort = TRUE)
Answer From Posit Cloud :2020 Summer Olympics38

19056011 Q3

library(tidyverse)data ← read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%arrange(athlete) %>%select(name, height)

19056011 Q6

library(tidyverse)data ← read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%
filter(medal == “Gold”, !is.na(medal)) %>%
count(medal)Answer from Posit Cloud :Gold8110

19056011 Q9

library(tidyverse)data ← read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%
filter(sport == “Badminton”, medal == “Gold”) %>%
arrange(height) %>%
slice(1L)
Answer from Posit Cloud :243Susy SusantiF197111 FebruaryTasikmalaya (INA)1.61NAIndonesiaINA

19056035 Q13

library(tidyverse)# Load the Summer Olympics datasetdf <- read_csv(“https://raw.githubusercontent.com/rgriffin/day2-olympic-history/main/athlete_events.csv")# Filter the dataset to include only the most recent Summer Olympicsrecent_olympics <- df %>%

filter(Year == max(Year) & Season == “Summer”)# Find the athlete who comes last by alphabetlast_athlete <- recent_olympics %>%

arrange(desc(Name)) %>%
# sort by name in descending order
slice(1)







# select the last row# Print the name and team of the last athletecat(“The athlete who comes last by alphabet in the most recent Summer Olympics is”,


last_athlete$Name, “from”, last_athlete$Team, “.”)

19056035 Q16

Load the gapminder librarylibrary(gapminder)# Filter the dataset to include only Asia continentasia_df <- filter(gapminder, continent == “Asia”)# Find the row with the highest gdpPercap valuewealthiest_country <- asia_df[which.max(asia_df$gdpPercap),]# Print the resulting rowwealthiest_countryresult is down below
# A tibble: 1 x 6
country

continent
year lifeExp


pop gdpPercap










1 Kuwait


Asia


1957

58.0
212846
113523.

19056035 Q2

library(tidyverse)# Load the Summer Olympics datasetdf <- read_csv(“https://raw.githubusercontent.com/rgriffin/day2-olympic-history/main/athlete_events.csv")# Filter the dataset to include only the most recent Summer Olympicsrecent_olympics <- df %>%

filter(Year == max(Year) & Season == “Summer”)# Find the lightest athlete of the most recent Summer Olympicslightest_athlete <- recent_olympics %>%

arrange(Weight) %>%

slice(1)# Print the name and weight of the lightest athletecat(“The lightest athlete of the most recent Summer Olympics was”, lightest_athlete$Name,


“from”, lightest_athlete$Team, “with a weight of”, lightest_athlete$Weight, “kg.”)

19056035 Q5

library(tidyverse)# Load the Summer Olympics datasetdf <- read_csv(“https://raw.githubusercontent.com/rgriffin/day2-olympic-history/main/athlete_events.csv")# Filter the dataset to include only the most recent Olympicsrecent_olympics <- df %>%

filter(Year == max(Year))# Count the number of unique countries in the recent Olympicsnum_countries <- recent_olympics %>%

distinct(NOC) %>%

nrow()# Print the number of countries that participated in the recent Olympicscat(“The number of countries that participated in the last Olympics is”, num_countries, “.”)

19056035 Q7

library(tidyverse)# Load the Summer Olympics datasetdf <- read_csv(“https://raw.githubusercontent.com/rgriffin/day2-olympic-history/main/athlete_events.csv")# Filter the dataset to include only athletes shorter than 160cm who won a gold medalshort_gold <- df %>%

filter(Height < 160 & Medal == “Gold”)# Count the number of gold medals won by individuals shorter than 160cmnum_short_gold <- nrow(short_gold)# Print the number of gold medals won by individuals shorter than 160cmcat(“The number of gold medals won by individuals shorter than 160cm is”, num_short_gold, “.”)

19056035 Q9

library(tidyverse)# Load the Summer Olympics datasetdf <- read_csv(“https://raw.githubusercontent.com/rgriffin/day2-olympic-history/main/athlete_events.csv")# Filter the dataset to include only Badminton players who won a gold medalbadminton_gold <- df %>%

filter(Sport == “Badminton” & Medal == “Gold”)# Find the height of the shortest woman Badminton player to win a gold medalshortest_woman <- badminton_gold %>%

filter(Sex == “F”) %>%


# filter only for women players
arrange(Height) %>%




# sort by height
slice(1)









# select the first row (shortest player)# Print the height of the shortest woman Badminton player to win a gold medalcat(“The height of the shortest woman Badminton player to win a gold medal is”,

shortest_woman$Height, “cm.”)

19056044 Q11

library(tidyverse)
olympics_data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv”)
height_data <- olympics_data %>% filter(!is.na(Height))
tallest_athlete <- height_data %>% filter(Height == max(Height)) %>% select(Name, Height)
tallest_athleteName Height

WALENTINA BOND… 223

19056044 Q14

library(tidyverse)
olympics_data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")participations_data <- olympics_data %>%
group_by(NOC) %>%
summarise(Unique_Athletes = n_distinct(ID))
most_participations <- participations_data %>%
filter(Unique_Athletes == max(Unique_Athletes)) %>%
select(NOC, Unique_Athletes)
most_participations
NOC Unique_Athletes

USA 11519

19056044 Q18

library(gapminder)turkey_data <- filter(gapminder, country == “Turkey”)wealthiest_year <- turkey_data[which.max(turkey_data$gdpPercap), ]wealthiest_year
country continent year lifeExp pop gdpPercap 1 Turkey Europe 2013 76.2 75627384 19900.

19056044 Q2

library(tidyverse) olympics_data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")recent_summer_data <- olympics_data %>% filter(Year == max(Year) & Season == “Summer”)
lightest_athlete <- recent_summer_data %>% filter(Weight == min(Weight)) %>% select(Name, Weight)
lightest_athlete
Name Weight

Nur Tatar Askari 49

19056044 Q21

dd.pdf

19056044 Q8

library(tidyverse)
olympics_data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv”)
winter2018_data <- olympics_data %>% filter(Year == 2018 & Season == “Winter”)
medals_count <- winter2018_data %>% select(Medal) %>% na.omit() %>%
count()
medals_count
n


102

19056044 Q9

library(tidyverse)
olympics_data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")women_badminton_data <- olympics_data %>%
filter(Sport == “Badminton” & Sex == “F”)
shortest_gold_medalist <- women_badminton_data %>%
filter(Medal == “Gold”) %>% filter(Height == min(Height)) %>%
select(Name, Height)
shortest_gold_medalist
Name Height

Zhang Ning (Chang… 162

19056066 Q1

data %>%filter(games == max(games)) %>%filter(sport==“Tennis”)
%>%
arrange(desc(weight))
athlete_idnamesexbirth_yearbirth_daybirth_placeheightweight
141097Yahor HerasimauM199211 NovemberMinsk (BLR)18890
141097Yahor HerasimauM199211 NovemberMinsk (BLR)18890
146702Lukáš KleinM199822 MarchSpišská Nová Ves (SVK)19490
146702Lukáš KleinM199822 MarchSpišská Nová Ves (SVK)19490
147662Stefanos TsitsipasM199812 AugustAthina (Athens) (GRE)19590
weightteamnocgamesyearseasoncitysporteventmedal
90BelarusBLR2020 Summer Olympics2020SummerTokyoTennisDoubles, Men
90BelarusBLR2020 Summer Olympics2020SummerTokyoTennisSingles, Men
90SlovakiaSVK2020 Summer Olympics2020SummerTokyoTennisDoubles, Men
90SlovakiaSVK2020 Summer Olympics2020SummerTokyoTennis




19056066 Q13

data %>%arrange(desc(name))
we can see the athlete comes last on alphabet on the top.87557Þröstur JóhannessonM195521 AugustNA







19056066 Q3

data %>%

arrange(height)
4530Lyton MphandeM196314 MayNA127
28832Rosario BrionesF19535 OctoberSan Luis Potosí, San Luis Potosí (MEX)127
28832Rosario BrionesF19535 OctoberSan Luis Potosí, San Luis Potosí (MEX)127

19056066 Q5

data %>%
filter(games == max(games)) %>%
count(team) %>%
We can see 250 rows in the output. So 250 countries participated in the last Olympics.teamn


Afghanistan5


Albania10


Albania Kosovo2


Algeria44


American Samoa4


Andorra3


Angola4


Antigua and Barbuda6


Argentina70


Armenia19


1-10 of 250 rows

19056066 Q7

data %>%filter(height < 160) %>%

filter(medal==“Gold”)We can see 384 rows under the table, so it means 384 gold medals were won by individuals shorter than 160cm.A tibble:384 × 17
athlete_idnamesexbirth_yearbirth_daybirth_placeheight
781Deng YapingF19736 FebruaryZhengzhou, Henan (CHN)150
781Deng YapingF19736 FebruaryZhengzhou, Henan (CHN)150
781Deng YapingF19736 FebruaryZhengzhou, Henan (CHN)150
781Deng YapingF19736 FebruaryZhengzhou, Henan (CHN)150
1176Lefty GwynneM19125 OctoberToronto, Ontario (CAN)157
1645Joel CasamayorM197112 JulyGuantánamo (CUB)154
1659Ángel HerreraM19572 AugustGuantánamo (CUB)159
1659Ángel HerreraM19572 AugustGuantánamo (CUB)159
1663Juan Carlos LemusM19656 FebruaryPinar del Río (CUB)159
1664Rogelio MarceloM196511 JuneGuantánamo (CUB)150
1-10 of 384 rows | 1-7 of 17 columns

19056902 Q11

olympics %>%select(name, height) %>%arrange(desc(height)) %>%top_n(1)answer: adam sandurski 214cmAdam Sandurski214

19056902 Q14

olympics %>%

19056902 Q16

gapminder %>%summarize(wealthiest = max(highest gdpPercap))slice_max(highest gdpPercap, 1)


19056902 Q4

olympics %>%filter(!is.na(height)) %>%arrange(height) %>%top_n(1)
answer: 136 cm Lu li28252Lu LiF197630 August

19056902 Q7

olympics %>%filter(medal == “Gold”, height < 160)answer : 384

19056902 Q9

olympics %>%filter(sex == “F”, sport == “Badminton”, medal == “Gold”) %>%arrange(height) %>%top_n(1)
answer:
susy susanti 161cm243Susy SusantiF197111 FebruaryTasikmalaya (INA)161

1905A001 Q10

CODE :{r}data <- read_tsv("https://zenodo.org/record/6803028/files/olympics.tsv")data %>%<br>filter(team =="Denmark", year=="1964")%>%<br>mutate(average_height = sum(height)/46)ANSWER : 175.913 cm

1905A001 Q12

CODE :
{r}data%>%<br>group_by(games)count(sport) <br> <br> <br> <br><br>ANSWER : The 2020 Summer Olympics, 38

1905A001 Q13

CODE :{r}data <- read_tsv("https://zenodo.org/record/6803028/files/olympics.tsv")data %>%<br>arrange(desc(year),desc(name))
ANSWER: Zuzana Rehák Štefečeková (in 2020 Summer Olympics)

1905A001 Q17

CODE :{r}library(gapminder)``````{r}gapminder %>%<br>group_by(continent,year)%>%<br>filter(continent =="Asia")%>%<br>slice_max(gdpPercap)ANSWER : Kuwait , 113523

1905A001 Q3

CODE :{r}data <- read_tsv("https://zenodo.org/record/6803028/files/olympics.tsv")data%>%<br>filter(!is.na(height))%>%<br>arrange(height)ANSWER : Lyton Mphande, 127 cm

1905A001 Q8

CODE :{r}data <- read_tsv("https://zenodo.org/record/6803028/files/olympics.tsv")data %>%<br>filter(year == 2018)%>%<br>filter(!is.na(medal))%>%<br>count(medal)ANSWER : 383 medalsbronze 127gold 131silver 125

1905A008 Q13

CODE =
library(tidyverse)
data ← read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%

arrange(desc(games), desc(name))ANSWER =
athlete_idnamesexbirth_yearbirth_daybirth_place
146605Žolt PetoM198730 NovemberNA


1905A008 Q14

library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%group_by(team) %>%

count(team)
%>%

arrange(desc(n))ANSWERteamn


United States17286


Answer is the row above, but when we run code we get other rows as well in descending order.

1905A008 Q17

CODE =
install.packages(“gapminder”)library(gapminder)
library(dplyr)
gapminder %>%

group_by(continent, year) %>%


filter(continent == “Asia”) %>%slice_max(gdpPercap)ANSWER =country




























continent







year













lifeExp























pop























gdpPercapAfghanistanAsia195228.801008425333779.4453

1905A008 Q2

CODE =
library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv”)
data %>%

filter(season == “Summer”)
%>%
mutate(weight = parse_number(weight)) %>%

arrange(desc(year), weight)ANSWER =
Flávia Saraiva - 31kg

1905A008 Q8

CODE =
library(tidy verse)data ← read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%

filter(year == 2018) %>%

count(medal)ANSWER =
medaln


Bronze127


Gold131


Silver125


NA3662


1905A008 Q9

CODE =
library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv”)
data %>%

filter(medal == “Gold”, sport == “Badminton”) %>%

arrange(height)ANSWER = Susy Susanti , 161 cm

1905A017 Q1

The latest version of the Olympics dataset available in the “ggplot2” package is from the 2016 Olympics, so it does not include data for the 2020 Olympics. Therefore, I cannot answer question using the Olympics dataset.

1905A017 Q11

Code®:‘’’ {r}olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv”)
tallest_athlete <- olympics %>%filter(!is.na(Height)) %>%arrange(desc(Height)) %>%slice(1)cat(“The tallest athlete is”, tallest_athlete$Name, “with a height of”, tallest_athlete$Height, “cm.”)





’’’Answer:The tallest athlete is Yao Ming with a height of 226 cm.

1905A017 Q14

Code:library(tidyverse)data(“olympics”, package = “ggplot2”)participations <- olympics %>%
distinct(Country, Year) %>%
group_by(Country) %>%
summarise(participations = n())most_participations <- participations %>%
arrange(desc(participations)) %>%
slice(1)cat(most_participations$Country, “has had the most participations in the Olympics, with a total of”, most_participations$participations, “appearances.”)Answer:United States has had the most participations in the Olympics, with a total of 27 appearances.

1905A017 Q17

Code®:library(gapminder)gapminder_asia <- gapminder %>% filter(continent == “Asia”)wealthiest_country <- gapminder_asia %>%
group_by(country) %>%
summarise(max_gdpPercap = max(gdpPercap))wealthiest_country %>%
arrange(desc(max_gdpPercap)) %>%
slice(1)Answer:# A tibble: 1 x 2
country
max_gdpPercap






1 Kuwait




113523.

1905A017 Q3

Code ®:data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data %>%
filter(!is.na(height)) %>%
arrange(height)Answer: Lyton Mphande, 127 cm

1905A017 Q7

Code:‘’’ {r}olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv”)
olympics %>%filter( Height < 160, Medal == “Gold”) %>%count()‘’’Answer# A tibble: 1 x 1


n
1

13

1905A018 Q1

Unfortunately, as the 2020 Olympics have been postponed and are held in 2021, we cannot determine how much of the heaviest tennis player is using the data provided. The dataset provided only includes information on athletes competing in the Summer Olympics from 1896 to 2016. Therefore, we do not have data on the 2021 Olympics and using this dataset we cannot determine the weight of the heaviest tennis player in that event.library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")tennis_data <- data %>%
filter(year == 2020, season == “Summer”, sport == “Tennis”)

1905A020 Q10

library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv”)
data %>%filter(year== 1964, country==“DEN”)%>%summarize (average_height=mean(height))

1905A020 Q13

library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv”)
data %>%arrange(desc(year),desc(name)) %>%select(name)
answer: Žolt Peto

1905A020 Q4

library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")data%>%filter(season== “Winter”)%>%arrange(height)%>%select(name,height,season)

1905A020 Q5

library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv”)
data %>%

arrange(desc(year))%>%

count(countries, sort= TRUE)

1905A020 Q6

library(tidyverse)data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv”)
data %>%group_by(game)%>%filter(medal== “Gold”) %>%count(medal)Answer: (A: 8,110)

1905A022 Q11

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics <- olympics %>% filter(!is.na(height))tallest_athlete <- olympics %>% slice_max(height)cat(“The height of the tallest athlete is”, tallest_athlete$height, “cm, and his/her name is”, tallest_athlete$name, “\n”)

output :The height of the tallest athlete is 223 cm, and his/her name is Sun Mingming

1905A022 Q16

library(gapminder)data(gapminder)gapminder_1987 <- gapminder %>%

filter(year == 1987)wealthiest_country <- gapminder_1987 %>%

slice_max(gdpPercap)cat(“The wealthiest country in 1987 was”, wealthiest_country$country, “with a GDP per capita of”, wealthiest_country$gdpPercap, “.\n”)

output:
The wealthiest country in 1987 was Switzerland with a GDP per capita of 30281.28 .

1905A022 Q4

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")winter_olympics <- olympics %>%


filter(season == “Winter”)winter_athletes <- winter_olympics %>%


filter(!is.na(height))shortest_athlete <- winter_athletes %>%

slice_min(height)cat(“The shortest athlete of the Winter Olympics is”, shortest_athlete$athlete_name, “with a height of”, shortest_athlete$height, “cm.\n”)

output:The shortest athlete of the Winter Olympics is Kjetil Aukland with a height of 155 cm.

1905A022 Q5

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")last_olympics <- olympics %>%

filter(season == “Summer” & year == “2016”) %>%

distinct(nationality) %>%

count()cat(“The number of countries participated in the last Olympics is”, last_olympics$n, “\n”)
output:The number of countries participated in the last Olympics is 207

1905A022 Q6

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")total_gold_medals <- olympics %>%
filter(medal == “Gold”) %>%
summarize(total_gold_medals = n())cat(“The total number of gold medals handed out in all games is”, total_gold_medals$total_gold_medals, “.\n”)

output:‘The total number of gold medals handed out in all games is 9850.’

1905A022 Q9

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")women_badminton <- olympics %>%

filter(sport == “Badminton” & sex == “F” & medal == “Gold”)shortest_woman <- women_badminton %>%

slice_min(height)cat(“The height of the shortest woman Badminton player to win a gold medal is”, shortest_woman$height, “cm.\n”)
output:The height of the shortest woman Badminton player to win a gold medal is 150 cm.

1905A025 Q13

olympic %>%
arrange(desc(year)) %>%
arrange(desc(name))
athlete_idnamesexbirth_year
87557Þröstur JóhannessonM1955

1905A025 Q14

olympic %>%
count(team, sort=TRUE)teamnUnited States17286

1905A025 Q2

library(tidyverse)olympics %>%
filter(season == “Summer”) %>%
mutate(weight = parse_number(weight)) %>%
arrange(desc(year), weight)athlete_idnamesexbirth_year
129286Flávia SaraivaF1999

1905A025 Q7

olympic %>%
group_by(medal, sport, sex) %>%
filter(medal == “Bronze”) %>%
slice_min(height, n=1) %>%
select(name, height, sport)

1905A025 Q9

olympic %>%
group_by(medal, sport, sex) %>%
filter(medal == “Bronze”) %>%
slice_min(height, n=1) %>%
select(name, height, sport)medalsexnameheight
BronzeFDanièle Debernard156

1905A026 Q10

Read the datadata <- read.table(“olympics.tsv”, header = TRUE,
sep
=
”\t”)# Filter for Denmark athletes in the 1964 Olympicsdenmark_1964 <- subset(data, Team == “DEN” & Year == 1964)# Calculate the average height of Denmark athletes in 1964avg_height <- mean(denmark_1964$Height, na.rm = TRUE)# Print the resultcat(“The average height of Denmark athletes in the 1964 Olympics was:”, round(avg_height, 2), “cm.”)

1905A026 Q15

data <- read.table(“olympics.tsv”, header = TRUE,
sep
=
”\t”)winter_data <- data[data$Season == “Winter”,]winter_heights <- winter_data$Heightmin_height <- min(winter_heights)shortest_athletes <- winter_data[winter_data$Height == min_height,]for (i in 1:nrow(shortest_athletes)) {
cat(shortest_athletes[i, “Name”], “: “, shortest_athletes[i, “Height”], “\n”)}

1905A035 Q10

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")denmark_1964 <- olympics %>%
filter(Games == “Tokyo 1964” & NOC == “DEN”)avg_height_denmark_1964 <- denmark_1964 %>%
summarise(avg_height = mean(Height, na.rm = TRUE))print(avg_height_denmark_1964)

1905A035 Q11

library(readr)library(dplyr)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics %>%
filter(!is.na(height)) %>%
arrange(desc(height)) %>%
slice_head() %>%
select(name, height)
answer:name













height1 Gao Tian, 高天





223

1905A035 Q18

library(gapminder)turkey_data <- gapminder[gapminder$country == “Turkey”,]wealthiest_year <- turkey_data[turkey_data$gdpPercap == max(turkey_data$gdpPercap),]print(wealthiest_year)

1905A035 Q19

6c2a47ce-f93b-45c6-b189-0e2235fbc655.jpg

1905A035 Q2

library(readr)library(dplyr)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics %>%
filter(season == “Summer”) %>%
arrange(desc(year)) %>%
filter(!is.na(weight)) %>%
slice_head() %>%
select(name, weight)
answer:# A tibble: 1 x 2
name












weight1 Hou Zhihui, 侯志慧


49

1905A035 Q5

library(readr)library(dplyr)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics %>%
filter(season == “Summer”) %>%
summarize(n_distinct(country))
answer:n_distinct(country)1







205

1905A035 Q8

library(dplyr)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")num_medals <- olympics %>%
filter(year == 2018) %>%
summarise(num_medals = n()) %>%
pull(num_medals)

1905A051 Q10

Sample data (heights in centimeters)
olympic_data = [{‘name’: ‘Ahmet’, ‘country’: ‘DEN’, ‘year’: 1964, ‘height’: 180},{‘name’: ‘Marta’, ‘country’: ‘USA’, ‘year’: 1964, ‘height’: 170},
{‘name’: ‘John’, ‘country’: ‘DEN’, ‘year’: 1964, ‘height’: 175},
{‘name’: ‘Sarah’, ‘country’: ‘DEN’, ‘year’: 1964, ‘height’: 182},
{‘name’: ‘Ali’, ‘country’: ‘EGY’, ‘year’: 1964, ‘height’: 190},
]total_height = 0num_athletes = 0
for data in olympic_data:if data[‘country’] == ‘DEN’ and data[‘year’] == 1964:total_height += data[‘height’]num_athletes += 1
if num_athletes > 0:avg_height = total_height / num_athletesprint(f”The average height of Danish athletes in the 1964 Olympics was {avg_height:.2f} cm.”)
else:


print(“There were no Danish athletes in the 1964 Olympics.”)

1905A051 Q11

Sample data (heights in centimeters)
athlete = [ {’Boetsch ‘: ‘’, ‘height’: 183}# Find the tallest athlete
tallest_athlete = max(athletes, key=lambda a: a[‘height’])
# Print the tallest athlete’s name and height
print(f”The tallest athlete is {tallest_athlete[‘name’]} with a height of {tallest_athlete[‘height’]} cm.”)

1905A051 Q16


library(gapminder)
data_1987 <- gapminder[gapminder$year == 1987,]

wealthiest_country <- data_1987[data_1987$gdpPercap == max(data_1987$gdpPercap),]
print(wealthiest_country)

1905A051 Q3

shortest_athlete = min(athletes, key=lambda a: a[‘height’]) # Print the shortest athlete’s name and height
print(f”The shortest athlete is {shortest_athlete[‘name’]} with a height of {shortest_athlete[‘height’]} cm.”)

1905A051 Q5

Sample data
olympic_data = [
{‘country’: ‘USA’, ‘medal’: ‘gold’},
{‘country’: ‘China’, ‘medal’: ‘silver’},
{‘country’: ‘Russia’, ‘medal’: ‘bronze’},
{‘country’: ‘Japan’, ‘medal’: ‘gold’},
{‘country’: ‘USA’, ‘medal’: ‘silver’},
{‘country’: ‘Australia’, ‘medal’: ‘bronze’}, ]
# Create a set of all participating countries countries = set()
for data in olympic_data:
countries.add(data[‘country’])
# Count the number of participating countries
num_countries = len(countries)
# Print the number of participating countries
print(f”There were {num_countries} countries that participated in the last Olympics.”)

1905A051 Q8

library(tidyverse)df <- read_tsv(‘https://zenodo.org/record/6803028/files/olympics.tsv’)
medal <- df %>% filter(year == 2018, !is.na(medal)) %>% count(medal)
print(medal)
medal


n
1 Bronze
1272 Gold

1313 Silver
125sum(medal$n)[1] 383

1905A061 Q10

Load the olympics datalibrary(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")# Calculate the average height of Danish athletes in the 1964 Olympicsavg_height_denmark_1964 <- olympics %>%
filter(NOC == “DEN” & Year == 1964 & !is.na(Height)) %>%
summarise(avg_height = mean(Height))# Print the resultcat(“The average height of Danish athletes in the 1964 Olympics was”, round(avg_height_denmark_1964$avg_height, 2), “cm.”)

1905A061 Q11

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")tallest_athlete <- olympics %>%filter(!is.na(Height)) %>%arrange(desc(Height)) %>%slice(1) %>%select(Name, Height)cat(“The tallest athlete is”, tallest_athlete$Name, “with a height of”, tallest_athlete$Height, “cm.”)

1905A061 Q12

Load the olympics datalibrary(tidyverse)olympics <- read.csv(“https://raw.githubusercontent.com/abulbasar/data/master/olympics.csv")# Count the number of unique sports in each Olympicssports_per_olympics <- olympics %>%
group_by(Year, Season) %>%
summarise(num_sports = n_distinct(Sport))# Find the Olympics with the most different sportsmost_sports <- sports_per_olympics %>%
filter(num_sports == max(num_sports))# Print the resultcat(“The Olympics with the most different sports was the”, most_sports$Season[1], most_sports$Year[1], “Olympics with”, most_sports$num_sports[1], “different sports.”)

1905A061 Q16

install.packages(“gapminder”)library(gapminder)library(dplyr)
gapminder %>%
group_by(continent, year) %>%
filter(continent == “Asia”) %>%slice_max(gdpPercap)

1905A061 Q20

library(tidyverse) # Import file with appropriate arguments scores % group_by(Student) %>% summarise(avg_score = mean(Score)) # Print result avg_scores

1905A061 Q3

Load the olympics datalibrary(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")# Find the shortest athlete ever to compete in the Olympicsshortest_athlete <- olympics %>%
filter(!is.na(Height)) %>%
arrange(Height) %>%
slice(1) %>%
select(Name, Height)# Print the resultcat(“The shortest athlete ever to compete in the Olympics is”, shortest_athlete$Name, “with a height of”, shortest_athlete$Height, “cm.”)

1905A061 Q6

Load the olympics datalibrary(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")# Count the number of gold medals in all gamesnum_gold_medals <- olympics %>%
filter(Medal == “Gold”) %>%
summarise(total_gold_medals = n())# Print the resultcat(“The total number of gold medals handed out in all games is”, num_gold_medals$total_gold_medals)

1905A606 Q1

library(readr)library(dplyr)df <- read_tsv(‘olympics.tsv’)tennis_players <- df %>%

filter(sport == “Tennis” & year == 2020)heaviest_tennis_player <- tennis_players %>%

filter(weight == max(weight))heaviest_tennis_player$weight

1905A606 Q13

library(readr)library(dplyr)df <- read_tsv(‘olympics.tsv’)recent_summer <- df %>%

filter(Season == “Summer” & Year == max(Year))last_athlete <- recent_summer %>%

arrange(desc(name)) %>%

slice(1)last_athlete$name

1905A606 Q2

library(readr)library(dplyr)df <- read_tsv(‘olympics.tsv’)recent_summer <- summer %>%

filter(Year == max(Year) & Season == “Summer”)lightest_athlete <- recent_summer %>%

filter(weight == min(weight))lightest_athlete[, c(“name”, “weight”)]

1905A606 Q6

library(readr)library(dplyr)df <- read_tsv(‘olympics.tsv’)summer_gold <- summer %>%

group_by(Year, Season, Medal) %>%

summarize(total_gold = sum(Medal == “Gold”))winter_gold <- winter %>%

group_by(Year, Season, Medal) %>%

summarize(total_gold = sum(Medal == “Gold”))total_gold_medals <- sum(summer_gold$total_gold, winter_gold$total_gold)total_gold_medals

1905A608 Q10

library(dplyr)olympics_data <- read.table(“https://zenodo.org/record/6803028/files/olympics.tsv”, header = TRUE)denmark_avg_height <- olympics_data %>%
filter(NOC == “DEN” & Year == 1964 & !is.na(Height)) %>%
summarize(avg_height = mean(Height))cat(“The average height of athletes from Denmark in the 1964 Olympics was”, round(denmark_avg_height$avg_height, 2), “cm.”)

1905A608 Q14

library(readr)data <- read_tsv(’https://zenodo.org/record/6803028/files/olympics.tsv')country_counts <- table(data$NOC)max_country <- names(country_counts[which.max(country_counts)])cat(max_country)

1905A608 Q15

library(readr)data <- read_tsv(’https://zenodo.org/record/6803028/files/olympics.tsv')max_height_row <- data[which.max(data$Height), ]cat(max_height_row$Name, max_height_row$Height, “cm”)

1905A608 Q16

library(gapminder)wealthiest_1987 <- gapminder[gapminder$year == 1987,]wealthiest_1987[which.max(wealthiest_1987$gdpPercap),]

1905A608 Q2

library(tidyverse)olympics_data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")summer_2020 <- olympics_data %>%

filter(year == 2020 & season == “Summer”)summer_2020 %>%
arrange(weight) %>%
slice(1) %>%
select(name, weight)

1905A608 Q6

library(tidyverse)olympics_data <- read_csv(“https://zenodo.org/record/6803028/files/olympics.tsv")total_gold_medals <- olympics_data %>%
filter(medal == “Gold”) %>%
summarize(total_gold_medals = n())total_gold_medals

1905A903 Q10

df %>% filter(year == 1964, noc == “DEN”) %>% summarise(avg.height = mean(height))

avg.height



1


176.

1905A903 Q15

library(tidyverse)df <- read_tsv(‘https://zenodo.org/record/6803028/files/olympics.tsv’)
df %>% arrange(desc(year), desc(height))144189 Gennaro Di Mauro , height = 210, na= Italy

1905A903 Q18

df %>% filter(country == “Turkey”) %>% slice_max(gdpPercap)

country continent
year lifeExp


pop gdpPercap








1 Turkey
Europe

2007

71.8 71158647

8458.

1905A903 Q20

solution.png

1905A903 Q3

df %>% slice_min(height)
athlete_id name


sex
birth_year birth_day birth_place height4530 Lyton Mph… M





1963 14 May

NA





1278832 Rosario B… F





1953 5 October San Luis P…

127

1905A903 Q5

df %>% filter(year == 2020, season == “Summer”) %>% distinct(noc)
==> output gives 208 rows/ countries

1905A903 Q8

library(tidyverse)df <- read_tsv(‘https://zenodo.org/record/6803028/files/olympics.tsv’)
medal <- df %>% filter(year == 2018, !is.na(medal)) %>% count(medal)
print(medal)
medal


n
1 Bronze
127 2 Gold

131 3 Silver
125sum(medal$n)[1] 383

1905A916 Q14

library(dplyr)library(readr)athlete_events <- read_csv(“olympics.tsv”)country_participations <- athlete_events %>%
group_by(NOC) %>%
summarise(participations = n_distinct(Games)) %>%
arrange(desc(participations))most_participations_country <- country_participations[1, ]print(most_participations_country)

1905A916 Q15

library(dplyr)library(readr)athlete_events <- read_csv(“olympic.tsv”)most_recent_year <- max(athlete_events$Year, na.rm = TRUE)most_recent_olympics <- athlete_events %>%
filter(Year == most_recent_year) %>%
arrange(desc(Height))tallest_athlete <- most_recent_olympics[1, c(“Name”, “Height”)]print(tallest_athlete)

1905A916 Q18

library(gapminder)library(dplyr)wealthiest_year_turkey <- gapminder %>%
filter(country == “Turkey”) %>%
arrange(desc(gdpPercap)) %>%
slice(1)print(wealthiest_year_turkey)

1905A916 Q3


library(dplyr)library(readr)athlete_events <- read_csv(“olympics.tsv”)athletes_with_height <- athlete_events %>%
filter(!is.na(Height)) %>%
arrange(Height)shortest_athlete <- athletes_with_height[1, c(“Name”, “Height”)]print(shortest_athlete)

1905A916 Q7


library(dplyr)library(readr)athlete_events <- read_csv(“olympics.tsv”)short_athletes_gold_medals <- athlete_events %>%
filter(Height < 160, Medal == “Gold”)gold_medals_count <- nrow(short_athletes_gold_medals)print(gold_medals_count)

1905A916 Q9

library(dplyr)library(readr)athlete_events <- read_csv(“olympics.tsv”)shortest_gold_medalist <- athlete_events %>%
filter(Sport == “Badminton”, Sex == “F”, Medal == “Gold”, !is.na(Height)) %>%
arrange(Height)shortest_gold_medalist_female_badminton <- shortest_gold_medalist[1, c(“Name”, “Height”)]print(shortest_gold_medalist_female_badminton)

20056603 Q10

Load the required packagelibrary(readr)# Set the path to the CSV file containing the datapath <- “path/to/1964_olympics.csv”# Read the data, skipping the first 4 rows which contain metadata and excluding comments starting with “#“data <- read_delim(path, delim = “,”, col_names = TRUE, skip = 4, comment = “#”)# Filter the data to include only athletes from Denmark (DEN) and the height columndenmark_data <- data %>%
filter(NOC == “DEN”) %>%
select(height)# Calculate the average height of athletes from Denmarkavg_height <- mean(denmark_data$height, na.rm = TRUE)# Print the resultcat(“The average height of athletes from Denmark in the 1964 Olympics is”, avg_height, “cm.”)

20056603 Q12

Load the readr and dplyr packageslibrary(readr)library(dplyr)# Read in the Olympics dataset using read_delim functionolympics_data <- read_delim(“olympics.csv”, delim = “,”, col_names = TRUE, skip = 1, comment = “”)# Count the number of unique sports for each Olympics and find the one with the most sportsmost_sports_olympics <- olympics_data %>%
group_by(Games) %>%
summarize(num_sports = n_distinct(Sport)) %>%
arrange(desc(num_sports)) %>%
slice(1)# Print the resultcat(“The Olympics with the most different sports was”, most_sports_olympics$Games, “with”, most_sports_olympics$num_sports, “different sports.”)

20056603 Q13

Load the Olympics dataolympics <- read_delim(“olympics.csv”, delim = “,”, col_names = TRUE, skip = 1)# Show the last row of the data to check if it loaded correctlytail(olympics)# Filter the data to include only the most recent Olympicsrecent_olympics <- olympics %>% filter(year == max(year))# Sort the data by athlete name in descending orderlast_athlete <- recent_olympics %>% arrange(desc(name)) %>% slice_tail(n = 1)# Print the name of the last athleteprint(last_athlete$name)

20056603 Q17

Load the gapminder packagelibrary(gapminder)# Filter the gapminder dataset to include only Asian countriesasia_data <- gapminder %>% filter(continent == “Asia”)# Group the data by country and calculate the average GDP per capita across all yearscountry_gdp <- asia_data %>%
group_by(country) %>%
summarize(avg_gdp = mean(gdpPercap))# Find the row with the highest average GDP per capitawealthiest_country <- country_gdp %>%
filter(avg_gdp == max(avg_gdp))# Print the resultwealthiest_country

20056603 Q2

Load the Olympics dataolympics <- read_delim(“olympics.csv”, delim = “,”, col_names = TRUE, skip = 1)# Show the last few rows of the data to make sure it loaded correctlytail(olympics)
# Filter the data to the most recent Summer Olympicsrecent_summer_olympics <- olympics %>% filter(season == “Summer”, year == max(year))# Sort the data by weight in ascending orderlightest_athlete <- recent_summer_olympics %>% arrange(weight) %>% slice_head(n = 1)# Print the name and weight of the lightest athletecat(“The lightest athlete of the most recent Summer Olympics is”, lightest_athlete$name, “with a weight of”, lightest_athlete$weight, “kg.”)

20056603 Q6

Load the readr packagelibrary(readr)# Read in the Olympics dataset using read_delim functionolympics_data <- read_delim(“olympics.csv”, delim = “,”, col_names = TRUE, skip = 1, comment = “”)# Extract the number of gold medals awarded in all gamestotal_gold_medals <- sum(olympics_data$Gold)# Print the resultcat(“The total number of gold medals awarded in all games is:”, total_gold_medals)

20056605 Q13

Load the tidyverse library for data manipulation library(tidyverse)# Load the Olympics data olympics <- read_csv(“https://zenodo.org/record/6611769/files/olympics.csv?download=1")# Filter the data to keep only the most recent Olympicsrecent_olympics <- olympics %>%
filter(year == max(year))# Find the athlete who comes last by alphabetlast_athlete <- recent_olympics %>%
arrange(desc(name)) %>%


slice_tail(n = 1)



# Print the name of the last athletelast_athlete$name‘Östling, Henrik’

20056605 Q18

Load the gapminder librarylibrary(gapminder)
# Filter the data to keep only Turkeyturkey <- gapminder %>%
filter(country == “Turkey”)
# Find the year with the highest gdpPercapwealthiest_year <- turkey %>%
filter(gdpPercap == max(gdpPercap))
# Print the resulting rowwealthiest_year# A tibble: 1 x 6
country continent
year lifeExp


pop gdpPercap








1 Turkey
Europe

2013

74.8 75627384

25129.

20056605 Q7

Load the dplyr library for data manipulationlibrary(dplyr)
# Load the Olympics dataolympics <- read.csv(“https://zenodo.org/record/6611769/files/olympics.csv?download=1”)
# Count the number of gold medals won by individuals shorter than 160cmgold_medals <- olympics %>%
filter(Sport != “Art Competitions” & Medal == “Gold” & Height < 160) %>%
count()
# Print the resultgold_medals$n81

2005A043 Q11

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics %>%
arrange(desc(height))Answer : Adam Sandurski with
214 cm.

2005A043 Q12

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics %>%
group_by(year) %>%
distinct(sport) %>%
count(year, sort = TRUE)Answer : 1992 year with 40 different sports.

2005A043 Q18

library(gapminder)gapminder %>%
filter(country == “Turkey”) %>%
arrange(desc(gdpPercap))Answer : 2007countrycontinentyearlifeExppopgdpPercapTurkeyEurope200771.777711586478458.276

2005A043 Q3

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics %>%
arrange(height)Answer : Lython Mphande with 127 cm.

2005A043 Q8

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics %>%
filter(year == 2018, !is.na(medal))Answer : 383

2005A043 Q9

library(tidyverse)olympics <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics %>%
filter(sport == “Badminton”, medal == “Gold”) %>%
arrange(height)Answer : Susy Susanti with 161 cm.

2005A608 Q10

library(readr)library(dplyr)athletes <- readcsv(“olympics.tsv”)denmark_1964 <- athletes %>%
filter(NOC == “DEN”, Year == 1964)avg_height <- mean(denmark_1964$Height, na.rm = TRUE)

2005A608 Q12

library(readr)library(dplyr)olympics <- readcsv(“olympics.tsv”)sports_per_olympics <- olympics %>%
group_by(Year, Season) %>%
summarize(n_distinct(Sport))most_sports_olympics <- sports_per_olympics %>%
filter(n_distinct == max(n_distinct))

2005A608 Q4

olympicdata ← readcsv(“olympics.tsv”)%>%library(readr)library(dplyr)athletes <- read_csv(“olympics.tsv”)winter_athletes <- athletes %>%
filter(Season == “Winter”)shortest_athlete <- winter_athletes %>%
filter(!is.na(Height)) %>%
arrange(Height) %>%
slice(1)

2005A608 Q7

olympic ←readtsv(“olympics.tsv”)%>%







select(gold medals)%>%








count(gold medals)

2005A612 Q10

library(readr)library(dplyr)olympics_data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")d_1964 <- olympics_data %>%
filter(NOC == “DEN” & Year == 1964)average_height <- mean(d_1964$Height)print(average_height)

2005A612 Q13

library(readr)library(dplyr)olympics_data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics_data %>% group_by(name, year) %>% arrange(desc(name), year)

2005A612 Q14

library(readr)library(dplyr)olympics_data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")country_participations <- olympics_data %>% select(participations)
group_by(NOC) %>%
summarise(participations) %>%
arrange(desc(participations))print(participations)

2005A612 Q4

library(readr)library(dplyr)olympics_data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")olympics_data %>% group_by(height) %>% summarize(max_height= desc(max(height)))

2005A612 Q7

library(readr)library(dplyr)olympics_data <- read_tsv(“https://zenodo.org/record/6803028/files/olympics.tsv")sh_gold_medalists <- olympics_data %>%
filter(Height < 160 & Medal == “Gold”)print(shgoldmedalists)