── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.2.1 ✔ readr 2.2.0
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.3 ✔ tibble 3.3.1
✔ lubridate 1.9.5 ✔ tidyr 1.3.2
✔ purrr 1.2.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(jsonlite)
Attaching package: 'jsonlite'
The following object is masked from 'package:purrr':
flatten
library(repurrrsive)
These are the questions I set out to explore:
List those who won more than once
Filter men and women. Calculate the proportion of women and men winners
Compare the proportion of men and women winners in economics against all the other disciplines combined.
Filter and combine winners by science and by continent of birth. I am thinking of continent rather than country because I would like to create a table and with many countries, it will be difficult to read.
The data
For this exercise data had to be requested from the Nobel Prize organization developer API. I was able to download the data and uploaded it in GitHub. From there I was able to retrieve them in R.
The Nobel Prize organization developer API provides two endpoints I have used both. I have explored their nested structure.
I started with the data frame “Winners”. I selected each winner’s ID to start creating a data frame (Winners_id) to use for my analysis.
At this point I realized I did not have all the winners. I have tried several times to go back to the Nobel Prize API and retrieve all of them. I did manage to do so every time. However, when converting it to a JSON file, it got truncated every time, Nevertheless, I decided to continue with the exercise with a smaller set of winners (which hampered some of the questions I wanted to explore).
id fileName gender
1 745 spence male
2 102 bohr male
3 779 ciechanover male
4 259 klug male
5 1004 gurnah male
6 114 salam male
7 982 banerjee male
8 981 abiy male
9 843 yonath female
10 866 riess male
11 199 butenandt male
12 164 baeyer male
13 185 windaus male
14 541 esquivel male
15 292 zewail male
16 853 suzuki male
17 978 yoshino male
18 819 gore male
19 1012 aspect male
20 729 heeger male
21 376 hodgkin male
22 730 macdiarmid male
23 11 michelson male
24 628 camus male
25 403 claude male
Selecting these variables was rather straightforward. Selecting the continent the winners are from was more difficult, given the nested structure. So I created a different data frame (Winners_loc).
en
1 North America
2 Europe
3 Asia
4 Europe
5 <NA>
6 Asia
7 Asia
8 Africa
9 Asia
10 North America
11 Europe
12 Europe
13 Europe
14 South America
15 Africa
16 Asia
17 Asia
18 North America
19 Europe
20 North America
21 Europe
22 Oceania
23 Europe
24 Africa
25 Europe
In order to be able to join these two data frames, I created a new variable (newid) in each data frame.
Winners_loc$newid <-1:nrow(Winners_loc)
Winners_id$newid <-1:nrow(Winners_id)
Then I created a new data frame (Winners_idloc), basically replicating (Winners_id). to be used for joining the two data frames.
As the categories (sciences) for each winner were deeply nested in the data frame Winners (at least for me), I found it easier to retrieve them from the NobelWinners data frame.
en
1 Chemistry
2 Literature
3 Peace
4 Physics
5 Physiology or Medicine
6 Chemistry
7 Literature
8 Peace
9 Physics
10 Physiology or Medicine
11 Chemistry
12 Literature
13 Peace
14 Physics
15 Physiology or Medicine
16 Chemistry
17 Literature
18 Peace
19 Physics
20 Physiology or Medicine
21 Chemistry
22 Literature
23 Peace
24 Physics
25 Physiology or Medicine
However, these 25 entries are not the same as the 25 in the other data frame Thus, I cannot join them.
I know they are not the same because, when analyzing the structure, I can see the names are different.
I have also tried unnesting from the Winners data frame.
The list with the categories is there. I just could not find a way to retrieve it.
The One Result
There are famous cases of persons who won more than one Nobel Prize (e.g. Marie Curie). However, I have used a truncated data set (he first 25 winners with first name starting with A). Thus, I did not find any repeat winner. I could not answer two of the remaining questions.
I could only answer (partially, as I had only 25 winners), the question about the proportion of women and men winners.
Grouping these winners by male and female is simple. Counting them and producing a bar graph to show them is also easy.
Winners_idloc|>group_by(gender)|>count()
# A tibble: 2 × 2
# Groups: gender [2]
gender n
<chr> <int>
1 female 1
2 male 24