缺失值替代

sqltxt <-"select ym_mc,xt_djjgdm from inoc_jzjl where jz_sj > =to_date('2018-01-01','yyyy-mm-dd')
and jz_sj <=to_date('2018-12-31','yyyy-mm-dd') and sfmf='1'"

dzmc <- con %>%
  tbl(in_schema('ipvsdb','SYS_XZQH_ZZJG')) %>%
  select(DZMC,DZBM) %>%
  filter(str_length(DZBM)==4) %>%
  collect() %>%
  clean_names()

vacc<- tbl(con,sql(sqltxt)) %>%
  collect() %>%
  clean_names()%>%
  mutate(shi=str_sub(xt_djjgdm,1,4)) %>%
  group_by(shi,ym_mc) %>%
  summarise(n=n()) %>%
  left_join(dzmc,by=c('shi'='dzbm')) %>%
  drop_na(dzmc) %>%
  spread(ym_mc,n) %>%
  mutate_all(list(~replace_na(.,0)))
  mutate_if(is.numeric,list(~replace_na(.,0)))

write.csv(vacc,'~//My Pictures//vacc.csv')

评论

此博客中的热门博文

V2ray websocket(ws)+tls+nginx分流

Rstudio 使用代理