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
270
データフレームを操作/how_to_manipulate_dataframes
florets1
June 08, 2023
Tweet
Share
More Decks by florets1
See All by florets1
請求と支払を照合する技術/using_full_join_in_r
florets1
1
78
応用セッション_同じデータでもP値が変わる話/key_considerations_in_NHST_2
florets1
1
870
お名前から性別を推測する/Guessing_gender_from_name
florets1
0
84
バタフライ効果/butterfly_effect
florets1
0
150
尤度/likelihood
florets1
3
770
同じデータでもP値が変わる話/key_considerations_in_NHST
florets1
1
1.1k
待ち行列のシミュレーション/queue_simulation
florets1
0
180
%hogehoge%で二項演算子/create_binary_operators_in_r_language
florets1
0
180
テーブルデータ大好き/Bidirectional and Composable Data Structure
florets1
1
710
Other Decks in Programming
See All in Programming
Balkan Ruby 2024 — How and why to run SQLite on Rails in production
fractaledmind
0
100
パフォーマンスを求めてDBに機能を寄せる戦略
aoyagikouhei
0
110
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
43
19k
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
1k
Code Reviews
bkuhlmann
4
900
『Railsオワコン』と言われる時代に、なぜブルーモ証券はRailsを選ぶのか
free_world21
1
370
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
utgwkk
6
1.8k
Elm 0.19.0 Changes
bkuhlmann
0
510
AppRouter Panel Talk
yosuke_furukawa
PRO
1
470
dbtのドメイン分割による データ基盤の改善とDigdagとの連携
sakama
0
450
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
9
4.3k
VS Code をプロダクトにどう取り込むか
onomax
1
740
Featured
See All Featured
Designing for Performance
lara
601
67k
4 Signs Your Business is Dying
shpigford
176
21k
Infographics Made Easy
chrislema
238
18k
Learning to Love Humans: Emotional Interface Design
aarron
267
39k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
660
120k
The Mythical Team-Month
searls
217
42k
Building an army of robots
kneath
300
41k
Designing Experiences People Love
moore
136
23k
GraphQLとの向き合い方2022年版
quramy
33
12k
Making the Leap to Tech Lead
cromwellryan
125
8.5k
Navigating Team Friction
lara
179
13k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
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() 入れ子を解除