如何做基线表
rm(list =ls())
setwd("C:\\Users\\17657\\Desktop\\ska3")
options(repos='http://cran.rstudio.com/')
library(xlsx)
baseline<- read.xlsx('临床信息.xlsx',sheetIndex = 1,header = T,encoding = 'UTF-8')
baseline<-baseline[1:1096,]
base<-subset(baseline,select = c(age,T,M,N,stage,ER,PR,HER2,subtype))
Freq<-lapply(base[,1:9],table)
prop<-lapply(Freq[1:9],prop.table)
prop
character<-c(names(Freq[1]),names(Freq[[1]]))
Noc<-c(NA,paste0(Freq[[1]],'(',prop[[1]],')'))
char<-NULL
characteristics<-data.frame('characteristics'=character,' number of class'=Noc)
for (i in 1:9) {character<-c(names(Freq[i]),names(Freq[[i]]))
Noc<-c(NA,paste0(Freq[[i]],'(',prop[[i]]*100,')'))
characteristics<-data.frame('characteristics'=character,' number of class(%)'=Noc)
char<-rbind(char,characteristics)
}
write.xlsx(char,'基线表.xlsx',col.names=T,row.names=F,showNA=F)
好啦可以啦~