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
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
47
Rで学ぶデータハンドリング入門/Introduction_to_Data_Handling_with_R
florets1
0
120
人工知能はクロスジョインでできている/AI_Is_Built_on_Cross_Joins
florets1
0
73
仮説の取扱説明書/User_Guide_to_a_Hypothesis
florets1
4
420
複式簿記から純資産を排除する/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
260
データハンドリング/data_handling
florets1
2
260
Other Decks in Programming
See All in Programming
JETLS.jl ─ A New Language Server for Julia
abap34
2
470
Flutter On-device AI로 완성하는 오프라인 앱, 박제창 @DevFest INCHEON 2025
itsmedreamwalker
1
180
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
400
2年のAppleウォレットパス開発の振り返り
muno92
PRO
0
180
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
470
Developing static sites with Ruby
okuramasafumi
1
340
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
160
Basic Architectures
denyspoltorak
0
160
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
640
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
240
生成AI時代を勝ち抜くエンジニア組織マネジメント
coconala_engineer
0
38k
AI Agent Dojo #4: watsonx Orchestrate ADK体験
oniak3ibm
PRO
0
120
Featured
See All Featured
Color Theory Basics | Prateek | Gurzu
gurzu
0
170
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
690
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.1k
Prompt Engineering for Job Search
mfonobong
0
140
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
76
Optimising Largest Contentful Paint
csswizardry
37
3.6k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
420
GraphQLの誤解/rethinking-graphql
sonatard
74
11k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.8k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
2.8k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
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() 入れ子を解除