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
420
0
Share
データフレームを操作/how_to_manipulate_dataframes
florets1
June 08, 2023
More Decks by florets1
See All by florets1
データ分析をはじめよう/lets_start_data_analysis
florets1
2
1k
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
720
Tableauとggplot2の背景/Background_of_Tableau_and_ggplot2
florets1
0
87
Rで学ぶデータハンドリング入門/Introduction_to_Data_Handling_with_R
florets1
0
150
人工知能はクロスジョインでできている/AI_Is_Built_on_Cross_Joins
florets1
0
110
仮説の取扱説明書/User_Guide_to_a_Hypothesis
florets1
4
480
複式簿記から純資産を排除する/eliminate_net_assets_from_double-entry_bookkeeping
florets1
1
490
カイ二乗検定は何をやっているのか/What_Does_the_Chi-Square_Test_Do
florets1
7
2.5k
直積は便利/direct_product_is_useful
florets1
3
480
Other Decks in Programming
See All in Programming
初めてのRubyKaigiはこう見えた
jellyfish700
0
410
TSKaigi 2026 TypeScriptバックエンドのオブザーバビリティ戦略 — Datadog × NestJSの実践
taiseiyamamotoan
2
270
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
550
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
130
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
6
800
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.3k
dRuby over BLE
makicamel
2
300
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
230
ふつうのFeature Flag実践入門
irof
7
3.5k
3Dシーンの圧縮
fadis
1
590
Swiftのレキシカルスコープ管理
kntkymt
0
210
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
440
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
22k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
250
ラッコキーワード サービス紹介資料
rakko
1
3.5M
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
320
Become a Pro
speakerdeck
PRO
31
6k
Deep Space Network (abreviated)
tonyrice
0
160
The agentic SEO stack - context over prompts
schlessera
0
790
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
The Spectacular Lies of Maps
axbom
PRO
1
780
How to make the Groovebox
asonas
2
2.2k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
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() 入れ子を解除