tagteam / Publish

R package Publish
15 stars 4 forks source link

Write excel file with a publish result #2

Closed Blanch-Font closed 9 years ago

Blanch-Font commented 9 years ago

Is it possible to write a Excel file with the Publish's output?

ekstroem commented 9 years ago

That is a super general question and as such very hard to answer. Could you provide a detailed example that shows exactly what you are looking for? Both an MWE in R code that shows what you produce and an explanation of what it should look like in Excel.

For example, do you mean:

  1. Store the output as a table and save that (with text, warts and everything) to a file that can be imported cell-by-cell into Excel?
  2. Save just the numbers so you can continue to work on the values in Excel?
  3. Something else?
Blanch-Font commented 9 years ago

I mean the first suggestion. I'm asking is possible to write the result of "publish(Cox model)" into a plain text separating the columns with a especial character.

Thank you for this faster response.

ekstroem commented 9 years ago

Well the output from publish is a data.frame so you can just write that as a .csv file and import it directly into Excel

library(survival)
data(pbc)
pbc$edema <- factor(pbc$edema,levels=c("0","0.5","1"),labels=c("0","0.5","1"))
fit = coxph(Surv(time,status!=0)~age+sex+edema+log(bili)+log(albumin)+log(protime), data=pbc)
res <- publish(fit) 
write.csv(res, file = "publishdata.csv")

To omit the row names you can add a row.names=FALSE argument to write.csv.