博文

目前显示的是 五月, 2020的博文

LBE 安装

if (!requireNamespace("BiocManager", quietly = TRUE))   install.packages("BiocManager") BiocManager::install(version = "3.11") if (!requireNamespace("BiocManager", quietly = TRUE))   install.packages("BiocManager") BiocManager::install("LBE") sudo R CMD javareconf JAVAC=/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/javac JAR=/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/jar JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/jar

计算接种率

#R 实现 inoc %>%   filter(str_sub(gldw_bm,1,2)=='62') %>%    mutate(yzyl=floor(day(as.period(interval(csrq,ymd('2021-01-25')),unit = "days"))/30)) %>%       filter(yzyl>=8 & yzyl<18) %>%    group_by(xian) %>%   summarise(deno=n_distinct(grda_et_lsh),num=sum(str_sub(ym_bm,1,2) %in% c('14') & jz_zc %in% c(1),na.rm = TRUE)) %>%   mutate(prec=round(num/deno*100,1)) %>%    left_join(xzqh,by=c('xian'='dzbm')) %>%    arrange(xian) Python实现 (inoc >>head( 1000 ) >>mutate( yzyl =((pd.to_datetime( '2021-01-25' )-_.csrq).dt.days/ 30 ), xian =_.gldw_bm.str[ 0 : 6 ]) >> filter (_.gldw_bm.str[ 0 : 2 ]== '62' ,_.yzyl>= 8 ) >>group_by(_.xian) >>summarize( n =n_distinct(_.grda_code), n3 =(((_.ym_bm.str[ 0 : 2 ]== '12' ) & (_.jz_zc== 1 )).sum( skipna = True ))) >>mutate( pert =np.round(_.n3/_.n* 100 , 2 )) >>arrange(_.xian) )

forcats包

library(tidyverse) x <- c("A","z","g",NA) x %>% as.factor()  # 默认按照字母排序 x %>% as_factor()  # 默认按照出现顺序排列 gss_cat$relig %>% fct_count() %>% arrange(-n) #fct_anon:用任意数字标识符替换因子级别 gss_cat$relig %>% fct_anon() %>% fct_count() %>% arrange(-n) gss_cat$relig %>% fct_anon("X") %>% fct_count() #fct_c:合并级别,连接因子 fa <- factor("a") fb <- factor("b") fab <- factor(c("a", "b")) c(fa, fb, fab) fct_c(fa, fb, fab) #fct_collapse:因子转换,将多个因子合并 fct_count(gss_cat$partyid) %>% arrange(n) partyid2 <- fct_collapse(gss_cat$partyid,                          missing = c("No answer", "Don't know"),                          other = "Other party",                          rep = c("Strong republican", "Not str republican"),                          ind = c("Ind,near rep", "Independent", "Ind,near