slots calculate for caac on s22
path <- r"(C:\Users\zhang\Documents\WeChat Files\wxid_1219792197912\FileStorage\File\2022-03\S22红头\S22红头)"
library(tidyr)
setwd(path)
pre <- list.files(path,‘二.+xls’) %>%
{l <- map(.,~readxl::read_xls(.,col_types = ‘text’));setNames(l,.)} %>%
bind_rows(.id = ‘source’) %>%
filter(FD23!=FD24)
pre_fix <-
pre %>%
{list(
select(.,1:4,FD4,FD5,FD21,FD26),
select(.,1:4,FD7,FD6,FD21,FD26),
select(.,1:4,FD7,FD8,FD21,FD26),
select(.,1:4,FD10,FD9,FD21,FD26),
select(.,1:4,FD10,FD11,FD21,FD26),
select(.,1:4,FD13,FD12,FD21,FD26)
)} %>%
map(~setNames(.,c(‘source’,‘fln’,‘type’,‘week’,‘loc’,‘slot’,‘nation’,‘kehuo’))) %>%
map(~filter(.,!is.na(slot),str_starts(loc,‘ZS’))) %>%
bind_rows() %>%
select(-1) %>% #解除文件标志
mutate(nation=ifelse(nation==‘港澳’,‘国际’,nation),
weeks=str_length(str_remove_all(week,’\.’)),
slotnum=as.integer(slot))
hd <- c(“ZSPD”,“ZSSS”,“ZSHC”,“ZSNJ”,“ZSAM”,“ZSQD”,“ZSFZ”,“ZSJN”,“ZSCN”,“ZSWZ”,“ZSNB”,“ZSOF”,“ZSYT”,“ZSQZ”,“ZSWX”,“ZSCG”,“ZSNT”,“ZSWH”,“ZSXZ”,“ZSYA”,“ZSLY”,“ZSSH”,“ZSGZ”,“ZSYN”,“ZSYW”,“ZSLG”,“ZSZS”,“ZSJG”,“ZSLQ”,“ZSRZ”,“ZSYC”,“ZSJU”,“ZSSR”,“ZSJH”,“ZSAQ”,“ZSLO”,“ZSWY”,“ZSJD”,“ZSTX”,“ZSGS”,“ZSFY”,“ZSWF”,“ZSDY”,“ZSSM”,“ZSWA”,“ZSHZ”,“ZSJJ”)
result <-
pre_fix %>%
{list(
tibble(loc=hd),
filter(.,nation==‘国内’,between(slotnum,0,600),kehuo==‘J’) %>% count(loc,wt=weeks),
filter(.,nation==‘国内’,!between(slotnum,0,600),kehuo==‘J’) %>% count(loc,wt=weeks),
filter(.,nation==‘国际’,between(slotnum,200,600),kehuo==‘J’) %>% count(loc,wt=weeks),
filter(.,nation==‘国际’,!between(slotnum,200,600),kehuo==‘J’) %>% count(loc,wt=weeks),
filter(.,nation==‘国内’,between(slotnum,0,600),kehuo==‘F’) %>% count(loc,wt=weeks),
filter(.,nation==‘国内’,!between(slotnum,0,600),kehuo==‘F’) %>% count(loc,wt=weeks),
filter(.,nation==‘国际’,between(slotnum,200,600),kehuo==‘F’) %>% count(loc,wt=weeks),
filter(.,nation==‘国际’,!between(slotnum,200,600),kehuo==‘F’) %>% count(loc,wt=weeks),
count(.,loc,wt=weeks)
)
} %>% reduce(left_join,by=‘loc’) %>%
setNames(c(‘loc’,‘内夜客’,‘内日客’,‘际夜客’,‘际日客’,‘内夜货’,‘内日货’,‘际夜货’,‘际日货’,‘all’))
result %>% clipr::write_clip()