Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
前処理R 第2回資料
mitti1210
April 23, 2022
Programming
0
230
前処理R 第2回資料
第2回 前処理R オンライン開催の発表資料です。
mitti1210
April 23, 2022
Tweet
Share
More Decks by mitti1210
See All by mitti1210
前処理勉強会_発表資料_MITTI_20210724.pdf
mitti1210
3
1k
Rによるオープンデータ 前処理勉強会(医療データ) _オープニング
mitti1210
3
1.7k
前処理をRでしたい! ~DPCデータに挑戦!~
mitti1210
2
100
Fukuoka.R #15 順序尺度の時系列変化を 折れ線グラフとヒートマップで 可視化してみた
mitti1210
1
10k
20190605_プログラム未経験者がMOOCでRを独学してみたら・・・
mitti1210
1
10k
Other Decks in Programming
See All in Programming
Loom is Blooming
josepaumard
3
540
バンドル最適化マニアクス at tfconf
mizchi
3
2.2k
Named Document って何?
harunakano
0
380
Kueue入門/Kueue Introduction
bells17
0
510
Is Rust a great language for building Kubernetes ecosystem
deepu105
0
140
A technique to implement DSL in Ruby
okuramasafumi
0
730
roadmap to rust 2024
matsu7874
1
800
クリエイティブ系のウェブサイト制作で役立つCSS技法 / CSS for develop creative website
clockmaker
2
1.6k
【PHPerKaigi2022】Mongo に溜まった約1.6億件の記事データを BigQuery へ …
userkazun
0
110
Git Rebase
bkuhlmann
7
1k
확장 가능한 테라폼 코드 관리 (Scalable Terraform Code Management)
posquit0
1
320
New Relicを使った Observabilityの実現方法と活用例 / gocon 2022 spring after talk
budougumi0617
0
1.1k
Featured
See All Featured
The Brand Is Dead. Long Live the Brand.
mthomps
45
2.7k
Why Our Code Smells
bkeepers
PRO
324
54k
Designing the Hi-DPI Web
ddemaree
272
32k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
37
3.2k
From Idea to $5000 a Month in 5 Months
shpigford
372
44k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
11
4.6k
Navigating Team Friction
lara
175
11k
Web development in the modern age
philhawksworth
197
9.3k
Writing Fast Ruby
sferik
612
57k
Why You Should Never Use an ORM
jnunemaker
PRO
47
5.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
498
130k
Designing on Purpose - Digital PM Summit 2013
jponch
106
5.6k
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!!