R 二类疫苗统计

library(dplyr)
df <- read.csv("C:\\Users\\xuefliang\\Desktop\\统计\\乙肝汉逊.csv")
df$year<- as.character(df$year)
df$diqu<- as.character(df$diqu)
df$pihao <- as.character(df$pihao)
df$goujin<- as.numeric(as.character(df$goujin))
df$shiyong<- as.numeric(as.character(df$shiyong))
#sum(df$goujin,na.rm=T)
#sum(df$shiyong,na.rm=T)

df$year[is.na(df$year)] <- ""

for(i in 1:nrow(df)){
  if (nchar(df$year)==0){
    df$year[i] <- df$year[i-1]
  }
}

for(i in 1:nrow(df)){
  if (df$year[i]==""){
    df$year[i] <- df$year[i-1]
  }
}

df$diqu[is.na(df$diqu)] <- ""

for(i in 1:nrow(df)){
  if (nchar(df$diqu)==0){
    df$diqu[i] <- df$diqu[i-1]
  }
}

for(i in 1:nrow(df)){
  if (df$diqu[i]==""){
    df$diqu[i] <- df$diqu[i-1]
  }
}

#按-拆分字符串
for(i in 1:nrow(df)){
  df$pihao[i] <- unlist(strsplit(df$pihao[i], "-"))[1]
}

result <- group_by(df,diqu,year,pihao)%>%
  summarise(tgoujin=sum(goujin,na.rm=T),tshiyong=sum(shiyong,na.rm=T))%>%
  mutate(number=1)%>%
  group_by(diqu,year)%>%
  summarise(pihaosum=sum(number),tgoujin=sum(tgoujin,na.rm=T),tshiyong=sum(tshiyong,na.rm=T))


write.csv(result,"C:\\Users\\xuefliang\\Desktop\\统计\\结果\\乙肝汉逊.csv")

评论

此博客中的热门博文

V2ray websocket(ws)+tls+nginx分流

Rstudio 使用代理