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
340
データフレームを操作/how_to_manipulate_dataframes
florets1
June 08, 2023
Tweet
Share
More Decks by florets1
See All by florets1
直積は便利/direct_product_is_useful
florets1
3
160
butterfly_effect/butterfly_effect_in-house
florets1
1
83
データハンドリング/data_handling
florets1
2
130
カイ二乗検定との遭遇/The_path_to_encountering_the_chi-square_test
florets1
1
180
率の平均を求めてはいけない/Do_Not_Average_Rates
florets1
10
15k
請求と支払を照合する技術/using_full_join_in_r
florets1
2
200
応用セッション_同じデータでもP値が変わる話/key_considerations_in_NHST_2
florets1
1
1.1k
お名前から性別を推測する/Guessing_gender_from_name
florets1
1
390
バタフライ効果/butterfly_effect
florets1
0
220
Other Decks in Programming
See All in Programming
個人開発で使ってるやつを紹介する回
yohfee
1
730
Competitionsだけじゃない! Kaggle Notebooks Grandmasterのすすめ
corochann
2
930
Re:proS_案内資料
rect
0
150
Subclassing, Composition, Python, and You
hynek
3
190
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
440
App Store Connect APIで 作業時間を増やそう
mot_techtalk
3
130
The future of development – Are our jobs getting harder or easier?
hollycummins
1
190
Memory API: Patterns, Use Cases, and Performance
josepaumard
2
200
フロントエンドの現在地とこれから
koba04
10
4.7k
Cloud Adoption Framework にみる組織とクラウド導入戦略
tomokusaba
2
680
CSC509 Lecture 03
javiergs
PRO
0
150
Новый уровень ML-персонализации Lamoda: Как мы усилили ее в каталоге и перенесли на другие продукты
lamodatech
0
390
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Speed Design
sergeychernyshev
23
540
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Practical Orchestrator
shlominoach
186
10k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
26
700
Product Roadmaps are Hard
iamctodd
PRO
48
10k
What's in a price? How to price your products and services
michaelherold
243
11k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
40
2.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
250
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Typedesign – Prime Four
hannesfritz
39
2.4k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
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() 入れ子を解除