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
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
180
テーブルデータ大好き/Bidirectional and Composable Data Structure
florets1
1
710
Other Decks in Programming
See All in Programming
TypeScriptの型とパフォーマンス (TSKaigi 2024)
ypresto
14
4.4k
最近コードレビューで指摘したこと
forrep
3
110
ts-morphを使ってコードリプレイスとASTへのハードルを下げる!
nyawach
5
320
Implementing Design Systems in Swift
seyfoyun
2
530
Sheets API使ってみた
toshi0383
2
180
Docker_OSS_ホスティング入門
satokoki645
0
140
Long journey of Ruby standard library RubyKaigi 2024
andpad
2
190
戦略的DDDは重いのか? / Is strategic DDD heavy?
pictiny
3
2.1k
The grand strategy of Ruby Parser
yui_knk
4
260
PHPコードの実行モデルを理解する / Understanding-the-PHP-Execution-Model
shin1x1
0
990
チーム立ち上げにAWSを活用したらClaudeさんに褒められた話
mkdev10
3
230
Try creating your own orderedmap
kazamori
1
280
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1357
200k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
8
3.5k
A Tale of Four Properties
chriscoyier
153
22k
Building a Scalable Design System with Sketch
lauravandoore
457
32k
4 Signs Your Business is Dying
shpigford
176
21k
Building Your Own Lightsaber
phodgson
100
5.7k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
26
2.3k
Designing for humans not robots
tammielis
247
25k
jQuery: Nuts, Bolts and Bling
dougneiner
60
7.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
1
120
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
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() 入れ子を解除