[R] Copying tables from R to Excel

Duncan Murdoch murdoch.duncan at gmail.com
Wed Sep 24 13:24:00 CEST 2014


On 24/09/2014, 6:32 AM, Angel Rodriguez wrote:
> Dear Ivan, Duncan, David and Roger,
> 
> Thank you for your answers. 
> 
> Yes, I had typed library(R2HTML)
> 
> I've typed also:
> 
>> library("mediation")
>> library("sandwich")
>> set.seed(2014)
>> med.fit <- glm(estuprimas ~ edad_c + sexo + regalf + deprinf, family="binomial" ,data=child65)
>> out.fit <- glm(benvii ~ edad_c + sexo + regalf + deprinf + estuprimas, family="binomial" ,data=child65)
>> med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estuprimas", robustSE = TRUE, sims=1000, control.value = "no", treat.value = "s\xed")
>> summary(med.out)

I don't know those packages, but I would assume that med.out is not a
dataframe or matrix.  What you'll need to do to get this to work is to
find out what class it is, and write an HTML.<whatever> method to handle
that class.  It probably won't involve actually writing an HTML, it'll
just be something like

HTML.<whatever> <- function(x, ...) {
  df <- < some code to create a dataframe containing the values you want
to transfer >
  HTML(df)
}

Duncan Murdoch

> 
> 
> If I type now:
> 
>> HTML( summary(med.out), file("clipboard", "w"), append=F )
> 
> I can paste to Excel but results are not organized in columns.
> 
> If I try:
> 
>> toExcel <- function(x, tag=FALSE) {write.table(x, "clipboard-128", sep="\t", row.names=tag)}
>>
>> toExcel(summary(med.out))
>  Show Traceback
>  
>  Rerun with Debug
>  Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
>   cannot coerce class "c("summary.mediate", "mediate")" to a data.frame 
> 
> 
> Angel Rodr�guez-Laso
> 
> 	[[alternative HTML version deleted]]
> 
> 
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list