www.crosshyou.info

政府統計の総合窓口のデータや、OECDやUCIやのデータを使って、Rの練習をしています。ときどき、読書記録も載せています。

短時間労働者の給与のデータの分析2 - R言語のgather関数とinner_join関数を使う。

 

www.crosshyou.info

 の続きです。

今回はR言語のgather関数とinner_join関数を使ってデータフレームをワイド型からロング型に変換します。

ワイド型というのは、

f:id:cross_hyou:20210403143545p:plain

こんな感じのデータです。

ロング型というのは

f:id:cross_hyou:20210403143755p:plain

こんな感じのデータです。

前回作成したデータフレーム、dfはワイド型なので、これをgather関数でロング型にします。

f:id:cross_hyou:20210403144001p:plain

f:id:cross_hyou:20210403144059p:plain

f:id:cross_hyou:20210403144154p:plain

f:id:cross_hyou:20210403144255p:plain

f:id:cross_hyou:20210403144344p:plain

f:id:cross_hyou:20210403144438p:plain

f:id:cross_hyou:20210403144528p:plain

これでyear, age, daysなどデータの種類ごとのロング型のデータフレームができました。

これらのデータフレームをinner_join関数で結合していきます。

f:id:cross_hyou:20210403144845p:plain

こんな感じです。

残りのデータフレームも同じように結合します。

f:id:cross_hyou:20210403145004p:plain

na.omit関数でNAの行を削除します。

f:id:cross_hyou:20210403145059p:plain

summary関数で全体の概要をみてみましょう。

f:id:cross_hyou:20210403145254p:plain

wageの平均値は1156円ですね。gendarが文字列なので、これをファクター型に変更します。

f:id:cross_hyou:20210403145722p:plain

今回は以上です。

次回は

 

www.crosshyou.info

 です。

はじめから読むには、

 

www.crosshyou.info

 です。