2012 and 2016 Summer Olympics Athlete Numbers
Introduction
With the start of the 2016 Summer Olympics in Rio and the parade of Athletes, I was interested in if there was more or less athletes than the previous. The Wikipedia’s Olympics pages [1][2] was used gather the information.
Data
Using rvest to scrape the data:
library(rvest)
urls <- c("https://en.wikipedia.org/wiki/2012_Summer_Olympics", "https://en.wikipedia.org/wiki/2016_Summer_Olympics")
dfs <- NULL
for (k in 1:length(urls)) {
webHTML <- tryCatch({read_html(urls[k])}, error=function(err) "Error") # attmpt to read website
if (all(webHTML != "Error")) {
htmlTable <- webHTML %>% html_nodes("table.wikitable:nth-child(1)") # get table
# countries
countries <- htmlTable %>% html_nodes(".thumbborder+ a") %>% html_text()
# number of participants are in the form (###), so remove '(' and ')'
participants <- gsub("\\(|)", "", htmlTable %>% html_nodes(".column-width span") %>% html_text())
dfs <- rbind(dfs, data.frame(country=countries, num.par=participants, year=strsplit(tail(strsplit(urls[k], "/")[[1]], 1), "_")[[1]][1], stringsAsFactors=F))
}
Sys.sleep(0.5)
}
dfs$num.par <- as.numeric(dfs$num.par)
From this, we get:
Event | City | Number.of.Countries | Number.of.Events |
---|---|---|---|
2012 Summer Olympics | London | 205 | 302 |
2016 Summer Olympics | Rio | 207 | 306 |
The following countries did not compete between in both Olympics: Kosovo, Kuwait, Refugee Olympic Team, South Sudan.
Since there are countries that competed in either 2012 or 2016 and not in the other, we will make a fix so that can easily take the diff of the two without causing an empty value to be returned.
# Values to add to 2016
dfs <- rbind(dfs, data.frame(country=setdiff(dfs$country[dfs$year == "2012"], dfs$country[dfs$year == "2016"]), num.par=0, year="2016", stringsAsFactors=F))
# Values to add to 2012
dfs <- rbind(dfs, data.frame(country=setdiff(dfs$country[dfs$year == "2016"], dfs$country[dfs$year == "2012"]), num.par=0, year="2012", stringsAsFactors=F))
dfs <- dfs[order(dfs$year, dfs$country),]
Now to take a look at the biggest changes in number of athletes:
Country | 2016 vs 2012 Athlete Difference |
---|---|
Brazil | 207 |
Great Britain | -175 |
Russia | -154 |
Argentina | 76 |
Netherlands | 67 |
France | 65 |
This makes sense as the host nations Brazil (2016) and Great Britain (2012) to have the biggest changes. Russia is special in this case as bans for doping has removed a large number of them.
A full list of all countries in alphabetical order is listed at the end.
Visulization
Most countries don’t have to much change in number of athletes except for a few but a weak trend towards more athletes participating in the 2016 games.
All Countries
Country | 2016 vs 2012 Athlete Difference |
---|---|
Afghanistan | -3 |
Albania | -6 |
Algeria | 25 |
American Samoa | -1 |
Andorra | -1 |
Angola | -9 |
Antigua and Barbuda | 4 |
Argentina | 76 |
Armenia | 8 |
Aruba | 3 |
Australia | 11 |
Austria | 1 |
Azerbaijan | 3 |
Bahamas | 4 |
Bahrain | 23 |
Bangladesh | 2 |
Barbados | 6 |
Belarus | -44 |
Belgium | -7 |
Belize | 0 |
Benin | 1 |
Bermuda | 0 |
Bhutan | 0 |
Bolivia | 6 |
Bosnia and Herzegovina | 5 |
Botswana | 8 |
Brazil | 207 |
British Virgin Islands | 2 |
Brunei | 0 |
Bulgaria | -12 |
Burkina Faso | 0 |
Burundi | 3 |
Cambodia | 0 |
Cameroon | -9 |
Canada | 37 |
Cape Verde | 2 |
Cayman Islands | 0 |
Central African Republic | 0 |
Chad | -1 |
Chile | 7 |
China | 17 |
Chinese Taipei | 16 |
Colombia | 43 |
Comoros | 1 |
Congo | 3 |
Cook Islands | 1 |
Costa Rica | -1 |
Croatia | -21 |
Cuba | 10 |
Cyprus | 3 |
Czech Republic | -28 |
Denmark | 9 |
Djibouti | 1 |
Dominica | 0 |
Dominican Republic | -6 |
DR Congo | 0 |
Ecuador | 2 |
Egypt | 7 |
El Salvador | -2 |
Equatorial Guinea | 0 |
Eritrea | 0 |
Estonia | 12 |
Ethiopia | -1 |
Federated States of Micronesia | -1 |
Fiji | 42 |
Finland | 1 |
France | 65 |
Gabon | -18 |
Georgia | 4 |
Germany | 33 |
Ghana | 5 |
Great Britain | -175 |
Greece | -9 |
Grenada | -4 |
Guam | -3 |
Guatemala | 2 |
Guinea | 1 |
Guinea-Bissau | 1 |
Guyana | 0 |
Haiti | 5 |
Honduras | -1 |
Hong Kong | -4 |
Hungary | 3 |
Iceland | -19 |
Independent Olympic Athletes | 5 |
India | 41 |
Indonesia | 6 |
Iran | 11 |
Iraq | 15 |
Ireland | 11 |
Israel | 11 |
Italy | 24 |
Ivory Coast | 2 |
Jamaica | 18 |
Japan | 45 |
Jordan | -1 |
Kazakhstan | -10 |
Kenya | 42 |
Kiribati | 0 |
Kosovo | 8 |
Kuwait | -11 |
Kyrgyzstan | 5 |
Laos | 3 |
Latvia | -12 |
Lebanon | -1 |
Lesotho | 4 |
Liberia | -2 |
Libya | 2 |
Liechtenstein | 0 |
Lithuania | 5 |
Luxembourg | 1 |
Macedonia | 2 |
Madagascar | -1 |
Malawi | 2 |
Malaysia | 2 |
Maldives | -1 |
Mali | 0 |
Malta | 2 |
Marshall Islands | 1 |
Mauritania | 0 |
Mauritius | 1 |
Mexico | 23 |
Moldova | 1 |
Monaco | -3 |
Mongolia | 14 |
Montenegro | 1 |
Morocco | -16 |
Mozambique | 0 |
Myanmar | 1 |
Namibia | 1 |
Nauru | 0 |
Nepal | 2 |
Netherlands | 67 |
New Zealand | 15 |
Nicaragua | -1 |
Niger | 0 |
Nigeria | 20 |
North Korea | -16 |
Norway | -2 |
Oman | 0 |
Pakistan | -14 |
Palau | 0 |
Palestine | 1 |
Panama | 3 |
Papua New Guinea | 0 |
Paraguay | 3 |
Peru | 13 |
Philippines | 2 |
Poland | 25 |
Portugal | 15 |
Puerto Rico | 17 |
Qatar | 26 |
Refugee Olympic Team | 10 |
Romania | -6 |
Russia | -154 |
Rwanda | 1 |
Saint Kitts and Nevis | 0 |
Saint Lucia | 1 |
Saint Vincent and the Grenadines | 1 |
Samoa | 0 |
San Marino | 1 |
São Tomé and Príncipe | 1 |
Saudi Arabia | -7 |
Senegal | -9 |
Serbia | -12 |
Seychelles | 4 |
Sierra Leone | 0 |
Singapore | 2 |
Slovakia | 4 |
Slovenia | -4 |
Solomon Islands | -1 |
Somalia | 0 |
South Africa | 12 |
South Korea | -43 |
South Sudan | 3 |
Spain | 24 |
Sri Lanka | 2 |
Sudan | 0 |
Suriname | 1 |
Swaziland | -1 |
Sweden | 18 |
Switzerland | 2 |
Syria | -3 |
Tajikistan | -9 |
Tanzania | 0 |
Thailand | 17 |
The Gambia | 2 |
Timor-Leste | 1 |
Togo | -1 |
Tonga | 4 |
Trinidad and Tobago | 2 |
Tunisia | -22 |
Turkey | -11 |
Turkmenistan | -1 |
Tuvalu | -2 |
Uganda | 5 |
Ukraine | -34 |
United Arab Emirates | -13 |
United States | 24 |
Uruguay | -12 |
Uzbekistan | 16 |
Vanuatu | -1 |
Venezuela | 17 |
Vietnam | 5 |
Virgin Islands | 0 |
Yemen | 0 |
Zambia | 0 |
Zimbabwe | 24 |