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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
florets1
June 08, 2023
Programming
0
400
データフレームを操作/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
480
Tableauとggplot2の背景/Background_of_Tableau_and_ggplot2
florets1
0
53
Rで学ぶデータハンドリング入門/Introduction_to_Data_Handling_with_R
florets1
0
130
人工知能はクロスジョインでできている/AI_Is_Built_on_Cross_Joins
florets1
0
83
仮説の取扱説明書/User_Guide_to_a_Hypothesis
florets1
4
430
複式簿記から純資産を排除する/eliminate_net_assets_from_double-entry_bookkeeping
florets1
1
450
カイ二乗検定は何をやっているのか/What_Does_the_Chi-Square_Test_Do
florets1
7
2.5k
直積は便利/direct_product_is_useful
florets1
3
450
butterfly_effect/butterfly_effect_in-house
florets1
1
270
Other Decks in Programming
See All in Programming
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
690
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
140
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
310
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
280
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1k
並行開発のためのコードレビュー
miyukiw
0
1k
生成AIを活用したソフトウェア開発ライフサイクル変革の現在値
hiroyukimori
PRO
0
100
高速開発のためのコード整理術
sutetotanuki
1
410
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
990
2026年 エンジニアリング自己学習法
yumechi
0
140
Featured
See All Featured
Paper Plane
katiecoart
PRO
0
46k
Embracing the Ebb and Flow
colly
88
5k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
380
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
410
[SF Ruby Conf 2025] Rails X
palkan
1
760
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
120
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
460
Technical Leadership for Architectural Decision Making
baasie
2
250
Evolving SEO for Evolving Search Engines
ryanjones
0
130
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
130
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
71k
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() 入れ子を解除