Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
データフレームを操作/how_to_manipulate_dataframes
Search
florets1
June 08, 2023
Programming
0
310
データフレームを操作/how_to_manipulate_dataframes
florets1
June 08, 2023
Tweet
Share
More Decks by florets1
See All by florets1
データハンドリング/data_handling
florets1
2
95
カイ二乗検定との遭遇/The_path_to_encountering_the_chi-square_test
florets1
1
140
率の平均を求めてはいけない/Do_Not_Average_Rates
florets1
10
14k
請求と支払を照合する技術/using_full_join_in_r
florets1
2
190
応用セッション_同じデータでもP値が変わる話/key_considerations_in_NHST_2
florets1
1
1k
お名前から性別を推測する/Guessing_gender_from_name
florets1
1
270
バタフライ効果/butterfly_effect
florets1
0
200
尤度/likelihood
florets1
3
830
同じデータでもP値が変わる話/key_considerations_in_NHST
florets1
1
1.2k
Other Decks in Programming
See All in Programming
【Go言語】golangci-lintの使い方
tomo1227
0
270
Ruby メモリ管理 プログラミング
megmogmog1965
0
130
CSC307 Lecture 10
javiergs
PRO
0
310
유연한 Composable 설계
l2hyunwoo
0
380
大規模マルチテナントを解決するYugabyteDBという選択肢
nnaka2992
1
250
Harnessing Large Language Models for Training-free Video Anomaly Detection
tereka114
1
1.3k
入社1ヶ月でここまでやった!Findy Toolsインフラ支援の最適化
rvirus0817
6
1.4k
さきがけから振り返るアーキテクチャ刷新 / Reflecting on the Architectural Renewal from the Vanguard
nrslib
2
770
DMMプラットフォームにおけるTiDBの導入から運用まで
pospome
7
3k
リハビリmruby
kishima
1
160
継続的な活動で築く地方エンジニアの道
myamashii
2
350
スクラムマスターって孤独じゃないですか?
yoshitaroyoyo
1
140
Featured
See All Featured
Pencils Down: Stop Designing & Start Developing
hursman
118
11k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
105
6.8k
Being A Developer After 40
akosma
72
580k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
35
6.3k
Clear Off the Table
cherdarchuk
89
320k
The Cost Of JavaScript in 2023
addyosmani
31
4.7k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
17
1.5k
Testing 201, or: Great Expectations
jmmastey
33
6.9k
The Straight Up "How To Draw Better" Workshop
denniskardys
229
130k
The Invisible Customer
myddelton
117
13k
What’s in a name? Adding method to the madness
productmarketing
PRO
21
2.9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
52k
Transcript
1 2023.06.10 Tokyo.R #106 データフレームを操作
Rでデータを加工してレポート
Tidyverse データの整形がはかどるライブラリ
← 代入
c() ベクトルを作る ベクトルの1番目の要素x[1]の値は0.3
▷ パイプライン x ^ 2 %>% sum %>% sqrt という書き方もあります。
tibble() データフレームを作る
この資料の表記ルール データフレームやCSVファイルのようなテーブル形状のデータを右図のように表記します。 =
架空の業務システム order_no 1 client AAA 1 abcd 2300 100 seq_no
unit_price item qty 2 efg 1500 90 (new)
order_no 1 client AAA orders (注文ヘッダー) 1 abcd 2300 100
seq_no unit_price item qty 2 efg 1500 90 (new)
1 abcd 2300 100 seq_no unit_price item qty 2 efg
1500 90 (new) details (注文明細) order_no 1 client AAA items (商品)
read_csv() ファイルを読み込む データフレーム(tibble)として読み込まれます。
行を抽出して列を選択する filter() とselect() ▷
inner_join() 結合する details orders × =
さらに結合する items × =
mutate() 列を追加する
結果をdに代入 d
在庫タイプ別の合計金額 ▷ d
注文番号ごとの合計金額 ▷ d
注文番号ごとの合計金額をsに代入 s ▷ d 注文番号ごとの合計金額
dとsを結合
注文番号ごとの割合
注文番号ごとの割合 nestとmapを使って書く例 中間変数無しで一気通貫に書ける
nestとmapの処理の流れ(1)
nestとmapの処理の流れ(2)
nestとmapの処理の流れ(3)
nestとmapの処理の流れ(4)
nestとmapの処理の流れ(5)
まとめ Tidyverse 便利なライブラリ ← 代入 C() ベクトル ▷ パイプライン tibble()
データフレーム read_csv() 読み込む filter() 抽出 select() 選択 inner_join() 結合 mutate() 列を追加 group_by() グループ化 summarise() 集計 group_nest() 入れ子にする map_dbl() リストに関数適用 ~ . ラムダ式 unnest() 入れ子を解除