-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.R
More file actions
32 lines (26 loc) · 767 Bytes
/
test.R
File metadata and controls
32 lines (26 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
library(tidyverse)
library(here)
clean_table <- function(table) {
d <- table %>%
filter(st == 53 & cnty %in% c('033', '035', '053', '061')) %>%
pivot_longer(cols = str_subset(colnames(table), "^T.*"),
names_to = 'header',
values_to = 'value') %>%
mutate(table = str_extract(header, "^T\\d*(?=_)"),
type = str_extract(header, "(?<=_)\\w{3}"),
sort = str_extract(header, "\\d+$"))
return(d)
}
dfs <- list()
csv <- paste0('Table', 1:5, '.csv')
for(i in 1:length(csv)) {
t <- read_csv(here('data', '050', csv[i]))
ct <- clean_table(t)
dfs[[csv[i]]] <- ct
}
# alternatives
# for(i in csv) {
# t <- read_csv(here('data', '050', c))
# ct <- clean_table(t)
# dfs[[c]] <- ct
# }