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
76
応用セッション_同じデータでもP値が変わる話/key_considerations_in_NHST_2
florets1
1
860
お名前から性別を推測する/Guessing_gender_from_name
florets1
0
73
バタフライ効果/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
170
テーブルデータ大好き/Bidirectional and Composable Data Structure
florets1
1
700
Other Decks in Programming
See All in Programming
SIMD Parallel Programming with the Vector API
josepaumard
0
190
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
280
Blue/Greenデプロイの導入による 運用フローの改善
kudoas
1
390
Rubyでたのしむクリエイティブコーディング/Enjoy Creative coding with Ruby
chobishiba
1
180
Site Reliability Engineering for GMO
pyama86
8
1k
効率化に挑戦してみたらモバイル開発が少し快適になった話
ryunakayama
0
130
禅の心を手に入れよ
eltociear
1
120
Scalable Customer Journey Orchestration (CJO)
lewuathe
0
350
使ってみよう Azure AI Document Intelligence
kosmosebi
2
330
Azure OpenAI Serviceのプロンプトエンジニアリング入門
tomokusaba
3
770
Goのmultiple errorsについて (2024年4月版)
syumai
4
980
Netty Chicago Java User Group 2024-04-17
sullis
0
180
Featured
See All Featured
Web development in the modern age
philhawksworth
202
10k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Building Your Own Lightsaber
phodgson
99
5.7k
We Have a Design System, Now What?
morganepeng
43
6.8k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Learning to Love Humans: Emotional Interface Design
aarron
267
39k
Building Better People: How to give real-time feedback that sticks.
wjessup
355
18k
How To Stay Up To Date on Web Technology
chriscoyier
782
250k
The Art of Programming - Codeland 2020
erikaheidi
42
12k
Scaling GitHub
holman
457
140k
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() 入れ子を解除