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
360
データフレームを操作/how_to_manipulate_dataframes
florets1
June 08, 2023
Tweet
Share
More Decks by florets1
See All by florets1
複式簿記から純資産を排除する/eliminate_net_assets_from_double-entry_bookkeeping
florets1
0
300
カイ二乗検定は何をやっているのか/What_Does_the_Chi-Square_Test_Do
florets1
6
2.1k
直積は便利/direct_product_is_useful
florets1
3
320
butterfly_effect/butterfly_effect_in-house
florets1
1
140
データハンドリング/data_handling
florets1
2
180
カイ二乗検定との遭遇/The_path_to_encountering_the_chi-square_test
florets1
1
240
率の平均を求めてはいけない/Do_Not_Average_Rates
florets1
11
15k
請求と支払を照合する技術/using_full_join_in_r
florets1
2
230
応用セッション_同じデータでもP値が変わる話/key_considerations_in_NHST_2
florets1
1
1.1k
Other Decks in Programming
See All in Programming
CI改善もDatadogとともに
taumu
0
110
GAEログのコスト削減
mot_techtalk
0
120
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
260
法律の脱レガシーに学ぶフロントエンド刷新
oguemon
5
740
密集、ドキュメントのコロケーション with AWS Lambda
satoshi256kbyte
0
190
Java Webフレームワークの現状 / java web framework at burikaigi
kishida
9
2.2k
PHPカンファレンス名古屋2025 タスク分解の試行錯誤〜レビュー負荷を下げるために〜
soichi
1
180
Conform を推す - Advocating for Conform
mizoguchicoji
3
690
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
46
17k
一休.com のログイン体験を支える技術 〜Web Components x Vue.js 活用事例と最適化について〜
atsumim
0
450
CNCF Project の作者が考えている OSS の運営
utam0k
6
710
Writing documentation can be fun with plugin system
okuramasafumi
0
120
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Testing 201, or: Great Expectations
jmmastey
42
7.2k
A Modern Web Designer's Workflow
chriscoyier
693
190k
A Tale of Four Properties
chriscoyier
158
23k
Facilitating Awesome Meetings
lara
52
6.2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Adopting Sorbet at Scale
ufuk
74
9.2k
Building an army of robots
kneath
303
45k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.4k
Six Lessons from altMBA
skipperchong
27
3.6k
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() 入れ子を解除