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
280
データフレームを操作/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
80
応用セッション_同じデータでもP値が変わる話/key_considerations_in_NHST_2
florets1
1
880
お名前から性別を推測する/Guessing_gender_from_name
florets1
0
110
バタフライ効果/butterfly_effect
florets1
0
160
尤度/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
190
テーブルデータ大好き/Bidirectional and Composable Data Structure
florets1
1
710
Other Decks in Programming
See All in Programming
ServerAction で Progressive Enhancement はどこまで頑張れるか? / progressive-enhancement-with-server-action
takefumiyoshii
6
520
JS RPCを理解する
yusukebe
5
290
Implementing Design Systems in Swift
seyfoyun
2
530
RustでAWS Lambda functionをいい感じに書く
taiki45
2
150
ts-morphを使ってコードリプレイスとASTへのハードルを下げる!
nyawach
5
330
AmperとFleetを使ったAndroidアプリ
yoppie
0
300
Effectで作る堅牢でスケーラブルなAPIゲートウェイ / Robust and Scalable API Gateway Built on Effect
yasaichi
7
1.2k
Slackワークフローで感謝を伝える機能/WiFi 自動接続/Figma to React Component/障害レポート君 Team3@NOT A HOTEL
nakaohiroshi
0
130
戦略的DDDは重いのか? / Is strategic DDD heavy?
pictiny
3
2.1k
チーム立ち上げにAWSを活用したらClaudeさんに褒められた話
mkdev10
3
230
The test code generator using static analysis and LLM
mikik0
1
230
Exploring Type-Informed Lint Rules in Rust based TypeScript Linters
unvalley
3
650
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
238
11k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
67
14k
Producing Creativity
orderedlist
PRO
338
39k
Thoughts on Productivity
jonyablonski
60
3.9k
Fireside Chat
paigeccino
22
2.7k
Building Your Own Lightsaber
phodgson
100
5.7k
Build The Right Thing And Hit Your Dates
maggiecrowley
25
2k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
StorybookのUI Testing Handbookを読んだ
zakiyama
13
4.7k
Designing with Data
zakiwarfel
96
4.8k
Large-scale JavaScript Application Architecture
addyosmani
504
110k
Fantastic passwords and where to find them - at NoRuKo
philnash
39
2.5k
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() 入れ子を解除