
130
9
章
tidyr
によるデータ整理
9.2
整理データ
同じ基本的なデータを表すのに複数の方法があります。次の例では、同じデータを4種類の異なる
方式で構成します。各データセットは、同じ4 つの変数
country
,
year
,
population
,
cases
の値を示
すのですが、それぞれのデータセットで値の構成方式が異なります
*1
。
table1
#> # A tibble: 6
×
4
#> country year cases population
#> <chr> <int> <int> <int>
#> 1 Afghanistan 1999 745 19987071
#> 2 Afghanistan 2000 2666 20595360
#> 3 Brazil 1999 37737 172006362
#> 4 Brazil 2000 804
88 174504898
#> 5 China 1999 212258 1272915272
#> 6 China 2000 213766 1280428583
table2
#> # A tibble: 12
×
4
#> country year type count
#> <chr> <int> <chr> <int>
#> 1 Afghanistan 1999 cases 745
#> 2 Afghanistan 1999 population 19987071
#> 3 Afghanistan 2000 cases 2666
#> 4 Afghanistan ...