R の pivot_wider 関数: データフレームの縦長、横長を変換する
UBC/informatics/r/pivot_wider
このページの最終更新日: 2025/01/05広告
pivot_wider() 関数の使い方
まずは使用データを準備する。組み込みデータセット の mtcars を使う。このデータは、以下のように車の種類が行に、mpg (マイル/ガロン、燃費の指標)、hp (馬力 horse power) などが列になっている。

これは


このデータ、mtcars_long を pivot_wider() 関数で元に戻す。mtcars_long がそもそも 3 列しかないので、pivot_longer よりもシンプルである。
広告
References
- 【R前処理講座23】tidyr pivot系:縦横変換【tidyverse】. Link: Last access 2023/07/25.
コメント欄
サーバー移転のため、コメント欄は一時閉鎖中です。サイドバーから「管理人への質問」へどうぞ。