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
初めてのKubernetes 本番運用でハマった話
oku053
0
120
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
180
ローカルLLMでどこまでコードが書けるか -縮小版 / How much code can be written on a local LLM Shortened
kishida
2
180
継続モナドとリアクティブプログラミング
yukikurage
3
450
えっ!!コードを読まずに開発を!?
hananouchi
0
160
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
200
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.7k
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.8k
Contextとはなにか
chiroruxx
1
390
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
130
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
200
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
300
Featured
See All Featured
Technical Leadership for Architectural Decision Making
baasie
3
440
The SEO Collaboration Effect
kristinabergwall1
1
500
Context Engineering - Making Every Token Count
addyosmani
9
1k
The Invisible Side of Design
smashingmag
301
52k
Exploring anti-patterns in Rails
aemeredith
3
440
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
600
The Language of Interfaces
destraynor
162
27k
Leo the Paperboy
mayatellez
8
1.9k
A designer walks into a library…
pauljervisheath
211
24k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.8k
From π to Pie charts
rasagy
0
230
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.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!!