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
430
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
データフレームを操作/how_to_manipulate_dataframes
florets1
June 08, 2023
More Decks by florets1
See All by florets1
整数計画ソルバーで遊ぼう/using_an_integer_programming_solver_in_r
florets1
0
42
データ分析をはじめよう/lets_start_data_analysis
florets1
2
1.1k
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
840
Tableauとggplot2の背景/Background_of_Tableau_and_ggplot2
florets1
0
100
Rで学ぶデータハンドリング入門/Introduction_to_Data_Handling_with_R
florets1
0
170
人工知能はクロスジョインでできている/AI_Is_Built_on_Cross_Joins
florets1
0
130
仮説の取扱説明書/User_Guide_to_a_Hypothesis
florets1
4
500
複式簿記から純資産を排除する/eliminate_net_assets_from_double-entry_bookkeeping
florets1
1
520
カイ二乗検定は何をやっているのか/What_Does_the_Chi-Square_Test_Do
florets1
7
2.6k
Other Decks in Programming
See All in Programming
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
2
1.5k
ALB ログから Trace を気合で繋げる技術
fohte
7
880
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
2.5k
typoなんかねぇよ
raspython3
0
670
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
Building an Out-of-Order CPU
latte72
1
720
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
200
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
55
36k
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
470
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
170
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
360
Featured
See All Featured
エンジニアに許された特別な時間の終わり
watany
108
250k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
270
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
810
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
680
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
820
For a Future-Friendly Web
brad_frost
183
10k
Docker and Python
trallard
47
4.2k
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() 入れ子を解除