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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
florets1
June 08, 2023
Programming
0
390
データフレームを操作/how_to_manipulate_dataframes
florets1
June 08, 2023
Tweet
Share
More Decks by florets1
See All by florets1
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
340
Tableauとggplot2の背景/Background_of_Tableau_and_ggplot2
florets1
0
49
Rで学ぶデータハンドリング入門/Introduction_to_Data_Handling_with_R
florets1
0
120
人工知能はクロスジョインでできている/AI_Is_Built_on_Cross_Joins
florets1
0
80
仮説の取扱説明書/User_Guide_to_a_Hypothesis
florets1
4
430
複式簿記から純資産を排除する/eliminate_net_assets_from_double-entry_bookkeeping
florets1
1
440
カイ二乗検定は何をやっているのか/What_Does_the_Chi-Square_Test_Do
florets1
7
2.4k
直積は便利/direct_product_is_useful
florets1
3
450
butterfly_effect/butterfly_effect_in-house
florets1
1
270
Other Decks in Programming
See All in Programming
AI 駆動開発ライフサイクル(AI-DLC):ソフトウェアエンジニアリングの再構築 / AI-DLC Introduction
kanamasa
11
5.7k
Pythonではじめるオープンデータ分析〜書籍の紹介と書籍で紹介しきれなかった事例の紹介〜
welliving
3
820
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
3.8k
dchart: charts from deck markup
ajstarks
3
970
高速開発のためのコード整理術
sutetotanuki
1
290
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
150
Python札幌 LT資料
t3tra
7
1.1k
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
530
CSC307 Lecture 04
javiergs
PRO
0
650
.NET Conf 2025 の興味のあるセッ ションを復習した / dotnet conf 2025 quick recap for backend engineer
tomohisa
0
120
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
180
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
A Tale of Four Properties
chriscoyier
162
24k
Rails Girls Zürich Keynote
gr2m
96
14k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.1k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
55
49k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.5k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
430
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
68
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
140
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
150
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
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() 入れ子を解除