Looking at the code below
library(pec)
data(GBSG2,package="pec")
setDT(GBSG2)
GBSG2
library(survival)
library(prodlim)
library(Publish)
cox_lung <- coxph(Surv(time,cens)~tgrade+age+strata(menostat)+tsize+pnodes+progrec+estrec,data=GBSG2)
publish(cox_lung,org=TRUE)
Output:
> publish(cox_GBSG2,org=TRUE)
| Variable | Units | HazardRatio | CI.95 | p-value |
|-----------+-------+-------------+-------------+-----------|
| tgrade | I | Ref | | |
| | II | 1.86 | [1.14;3.03] | 0.01276 |
| | III | 2.24 | [1.32;3.78] | 0.00263 |
| age | | 0.99 | [0.97;1.01] | 0.27167 |
| tsize | | 1.01 | [1.00;1.01] | 0.06029 |
| pnodes | | 1.05 | [1.04;1.07] | < 0.001 |
| progrec | | 1.00 | [1.00;1.00] | < 0.001 |
| estrec | | 1.00 | [1.00;1.00] | 0.70522 |
I'd like to know if there is an easy way to export the bove output to a CSV, word or excel file.
Here's a way to get a csv file using
capture.output
andgsub
. I'm displaying the intermediate steps as well:Rather than using
cat
perhaps would have been cleaner to usewrite.table
(since it avoids needing to add the linefeeds "by hand"):