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
前処理R 第2回資料
Search
mitti1210
April 23, 2022
Programming
430
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
前処理R 第2回資料
第2回 前処理R オンライン開催の発表資料です。
mitti1210
April 23, 2022
More Decks by mitti1210
See All by mitti1210
前処理勉強会_発表資料_MITTI_20210724.pdf
mitti1210
3
1.4k
Rによるオープンデータ 前処理勉強会(医療データ) _オープニング
mitti1210
3
2.1k
前処理をRでしたい! ~DPCデータに挑戦!~
mitti1210
2
250
Fukuoka.R #15 順序尺度の時系列変化を 折れ線グラフとヒートマップで 可視化してみた
mitti1210
1
13k
20190605_プログラム未経験者がMOOCでRを独学してみたら・・・
mitti1210
1
13k
Other Decks in Programming
See All in Programming
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
Contextとはなにか
chiroruxx
1
390
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
400
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
110
1B+ /day規模のログを管理する技術
broadleaf
0
130
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
810
継続モナドとリアクティブプログラミング
yukikurage
3
450
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
240
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
220
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
130
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
180
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
200
Featured
See All Featured
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
300
Done Done
chrislema
186
16k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
410
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
260
Information Architects: The Missing Link in Design Systems
soysaucechin
0
1k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
170
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
Producing Creativity
orderedlist
PRO
348
40k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Transcript
tryCatch @MITTI12101 2 # R (2022/04/23)
MITTI Edx Professional Certificate (Data Sciense) GCI GCI2019 Winter
病棟の機器を一日どのくらい使用しているか集計したい Excelのデータはあります いいですよ!
ここの平均が欲しい 数十ヶ月ある
この行だけ読み込めばOK? readxl::read_excel(range=”B25:AF25”) でも機器の数って変わってそう・・・
【作戦】 1, 1行目以外を読み込む 2, 計の行のみにする 3, A列を消して数字だけにする 4, 平均を計算する 完成予想
library(readxl) library(tidyverse) file <- "test.xlsx sheets <- excel_sheets(file) temp <-
read_excel(file, sheet = 1, skip = 1) temp %>% filter(...1 == " ") %>% select(-1) %>% rowMeans(na.rm = TRUE) [1] 8.677419 1 ReadSheet <- function(file, sheet){ temp <- read_excel(file, sheet = sheet, skip = 1) mean <- temp %>% filter(...1 == " ") %>% select(-1) %>% rowMeans(na.rm = TRUE) year <- str_extract(sheet, "^20[0-9][0-9]") month <- str_extract(sheet,"[0-9]*$") result <- tibble( year = as.integer(year), momth = as.integer(month), value = mean ) return(result) } ReadSheet(file, sheets[1]) [1] 8.677419
map_dfr(sheets,~ReadSheet(file, .x)) 1 1 map
for (sheet in sheets) { tryCatch( { ReadSheet(file, sheet) #
}, error = function(e){ print(paste0(sheet, )) # } ) } tryCatch
character
ReadSheet <- function(file, sheet){ temp <- read_excel(file, sheet = sheet,
skip = 1) mean <- temp %>% filter(...1 == " ") %>% select(-1) %>% mutate(across(everything(), as.numeric)) %>% # 1 rowMeans(na.rm = TRUE) year <- stringr::str_extract(sheet, "^20[0-9][0-9]") month <- stringr::str_extract(sheet,"[0-9]*$") result <- tibble( year = as.integer(year), momth = as.integer(month), value = mean ) return(result) } ReadSheet(file, sheets[7])
map_dfr(sheets,~ReadSheet(file, .x)) map
csv map tryCatch
ENJOY!!