$30 off During Our Annual Pro Sale. View Details »
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
390
データフレームを操作/how_to_manipulate_dataframes
florets1
June 08, 2023
Tweet
Share
More Decks by florets1
See All by florets1
Tableauとggplot2の背景/Background_of_Tableau_and_ggplot2
florets1
0
43
Rで学ぶデータハンドリング入門/Introduction_to_Data_Handling_with_R
florets1
0
110
人工知能はクロスジョインでできている/AI_Is_Built_on_Cross_Joins
florets1
0
70
仮説の取扱説明書/User_Guide_to_a_Hypothesis
florets1
4
420
複式簿記から純資産を排除する/eliminate_net_assets_from_double-entry_bookkeeping
florets1
1
430
カイ二乗検定は何をやっているのか/What_Does_the_Chi-Square_Test_Do
florets1
7
2.4k
直積は便利/direct_product_is_useful
florets1
3
440
butterfly_effect/butterfly_effect_in-house
florets1
1
250
データハンドリング/data_handling
florets1
2
250
Other Decks in Programming
See All in Programming
【CA.ai #3】ワークフローから見直すAIエージェント — 必要な場面と“選ばない”判断
satoaoaka
0
240
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
4
870
バックエンドエンジニアによる Amebaブログ K8s 基盤への CronJobの導入・運用経験
sunabig
0
160
Go コードベースの構成と AI コンテキスト定義
andpad
0
130
WebRTC、 綺麗に見るか滑らかに見るか
sublimer
1
160
Giselleで作るAI QAアシスタント 〜 Pull Requestレビューに継続的QAを
codenote
0
190
非同期処理の迷宮を抜ける: 初学者がつまづく構造的な原因
pd1xx
1
720
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
8
2.4k
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
160
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
410
Rediscover the Console - SymfonyCon Amsterdam 2025
chalasr
2
160
ハイパーメディア駆動アプリケーションとIslandアーキテクチャ: htmxによるWebアプリケーション開発と動的UIの局所的適用
nowaki28
0
420
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
390
We Have a Design System, Now What?
morganepeng
54
7.9k
The Pragmatic Product Professional
lauravandoore
37
7.1k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.4k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Bash Introduction
62gerente
615
210k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Designing for humans not robots
tammielis
254
26k
Speed Design
sergeychernyshev
33
1.4k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
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() 入れ子を解除