R 删除空行
library(xlsx)
library(dplyr)
workbook <- "C:\\Users\\Administrator\\Desktop\\合格\\兰州市汇总2010-2016年15种生物制品使用情况信息表().xlsx"
#表1
mydataframe <- read.xlsx2(workbook,1,startRow=3)
mydataframe$X..6 <- as.character(mydataframe$X..6)
mydataframe$X. <- as.character(mydataframe$X.)
mydataframe$X..5 <- as.character(mydataframe$X..5)
mydataframe$购进数量..支. <- as.numeric(as.character(mydataframe$购进数量..支.))
mydataframe$该批次生物制品使用数量..支. <- as.numeric(as.character(mydataframe$该批次生物制品使用数量..支.))
#删除空白行
num=c()
for(i in 1:nrow(mydataframe)){
if (nchar(mydataframe$X..5[i])==0){
num[i] <- i
}
}
mydataframe <- mydataframe[-num[!is.na(num)],]
for(i in 1:nrow(mydataframe)){
if (nchar(mydataframe$X.[i])==0){
mydataframe$X.[i] <- mydataframe$X.[i-1]
}
}
#按-拆分字符串
for(i in 1:nrow(mydataframe)){
mydataframe$X..6[i] <- unlist(strsplit(mydataframe$X..6[i], "-"))[1]
}
result <- select(mydataframe,year=X.,pihao=X..6,goujin=购进数量..支.,shiyong=该批次生物制品使用数量..支. )%>%
group_by(year,pihao)%>%
summarise(tgoujin=sum(goujin),tshiyong=sum(shiyong))
write.csv(result,"C:\\Users\\Administrator\\Desktop\\合格\\兰州\\冻干人用狂犬病疫苗(Vero细胞).csv")
library(dplyr)
workbook <- "C:\\Users\\Administrator\\Desktop\\合格\\兰州市汇总2010-2016年15种生物制品使用情况信息表().xlsx"
#表1
mydataframe <- read.xlsx2(workbook,1,startRow=3)
mydataframe$X..6 <- as.character(mydataframe$X..6)
mydataframe$X. <- as.character(mydataframe$X.)
mydataframe$X..5 <- as.character(mydataframe$X..5)
mydataframe$购进数量..支. <- as.numeric(as.character(mydataframe$购进数量..支.))
mydataframe$该批次生物制品使用数量..支. <- as.numeric(as.character(mydataframe$该批次生物制品使用数量..支.))
#删除空白行
num=c()
for(i in 1:nrow(mydataframe)){
if (nchar(mydataframe$X..5[i])==0){
num[i] <- i
}
}
mydataframe <- mydataframe[-num[!is.na(num)],]
for(i in 1:nrow(mydataframe)){
if (nchar(mydataframe$X.[i])==0){
mydataframe$X.[i] <- mydataframe$X.[i-1]
}
}
#按-拆分字符串
for(i in 1:nrow(mydataframe)){
mydataframe$X..6[i] <- unlist(strsplit(mydataframe$X..6[i], "-"))[1]
}
result <- select(mydataframe,year=X.,pihao=X..6,goujin=购进数量..支.,shiyong=该批次生物制品使用数量..支. )%>%
group_by(year,pihao)%>%
summarise(tgoujin=sum(goujin),tshiyong=sum(shiyong))
write.csv(result,"C:\\Users\\Administrator\\Desktop\\合格\\兰州\\冻干人用狂犬病疫苗(Vero细胞).csv")
评论
发表评论