问题描述
我正在尝试单变量cox回归并将结果从“发布”包导出到.csv文件,但是我遇到了这些错误
as.data.frame.default(x [[i]],可选= TRUE,stringsAsFactors = stringsAsFactors)中的错误: 无法将类别“ summary.regressionTable”强制转换为data.frame
我尝试了这里提到的另一种方法 (Export coxph summary from R to csv) 但这给了我这个错误
错误:此列表未识别整洁的方法。
假设以下是我的数据框和使用的代码,请告诉我您的宝贵意见。感谢您的努力。
data<-read.table(text="time status age gender race
15 1 70 f white
70 0 60 m black
212 1 65 m others
10 0 45 m black
20 1 30 f others
14 0 27 f white
36 0 65 m white
20.37097957 0 45 m white
44.01586607 1 30 f white
51.29873743 0 27 f white
8.253579038 1 70 f white
58.49852945 0 60 f white
32.44848147 1 65 m white
57.93159063 0 70 f white
64.62613556 1 60 f black
78.98468361 0 65 m others
15 1 70 f white
70 0 60 m black
212 1 65 m others
10 0 45 m black
20 1 30 f others
14 0 27 f white
36 0 65 m white
86.57105915 0 45 m white
89.1741374 1 30 f white
60.13106619 0 27 f white
26.0941471 1 70 f white
20.95514934 0 60 f white
99.4575019 1 65 m white
86.69263409 0 70 f white
212 1 65 m others
10 0 45 m black
20 1 30 f others
14 0 27 f white
36 0 65 m white
54.2720264 0 45 m white
91.77489557 1 30 f white
93.23043261 0 27 f white
47.9968136 1 70 f white
",header=T)
#################################################################################
library(broom);library(data.table);library(Publish)
library(survival);library(survminer);library(Hmisc);
dput(names(data))
covariates <- c("age","gender","race" )
univ_formulas <- sapply(covariates,function(x) as.formula(paste("Surv(time,status)~",x)))
univ_models <- lapply( univ_formulas,function(x){coxph(x,data = data)})
a<-Publish::publish(univ_models);a
UVA<-as.data.frame(a);write.csv(a,file="UVA.csv")
# Error in as.data.frame.default(x[[i]],optional = TRUE,stringsAsFactors = stringsAsFactors) :
# cannot coerce class ‘"summary.regressionTable"’ to a data.frame
#==================================
## Another approach (https://stackoverflow.com/questions/61482594/export-coxph-summary-from-r-to-csv)
out = tidy(a)
#Error: No tidy method recognized for this list.
class(out);out
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)