In R for Data Science, the authors explain their idea of tidy data. They give an example for data that is not tidy:
#> # A tibble: 3 x 3 #> country `1999` `2000` #> * <chr> <int> <int> #> 1 Afghanistan 19987071 20595360 #> 2 Brazil 172006362 174504898 #> 3 China 1272915272 1280428583
A tidy version of the same data, according to the authors, would be:
#> # A tibble: 6 x 3 #> country year population #> <chr> <chr> <int> #> 1 Afghanistan 1999 19987071 #> 2 Afghanistan 2000 20595360 #> 3 Brazil 1999 172006362 #> 4 Brazil 2000 174504898 #> 5 China 1999 1272915272 #> 6 China 2000 1280428583
I see that in the untidy version, one must already know that the data is population, otherwise it is impossible to understand, what
2000 mean. However, that could be derived from context, e.g. if the tibble is stored in a variable called
Now, who am I to doubt their judgment -- I do not. But I would like to better understand their idea. What are the actual advantages of the second version? I cannot not intuitively see them, e.g. calculation of mean etc. would be easy for both cases AFAICS, even if different functions need to be used. On the other hand, I would think that it is e.g. easier to calculate the correlation between the population of two years if the data is stored in the "untidy" form. What is my mistake here?