Sunday, August 7, 2016

Table from R to MS Word

Sometimes you have to cooperate with people who do not use LaTeX, and you have to use MS Word. I know it's awful, but here is a fast way to get your R tables into MS Word:

## generate example table:
airq <- subset(airquality, !
airct <- ctree(Ozone ~ ., data = airq)
mytable <- sctest(airct)[[1]]

## create table that can be opened in MS Word:
print(xtable(mytable), type="html", file="mytable.doc")

Now you will find a file called "mytable.doc" in the working directory. If you open it, you will find a table that you can edit and copy-paste to other MS Word documents.

Some hints if you want to manually adjust the table to APA lay-out:
- Click right somewhere in table
- Click ‘tabeleigenschappen’ (‘table properties’), then ‘opties’ (‘options’)
- Remove tickmark at ‘Standaardafstand tussen cellen’ (‘default cell spacing’)
- Click ‘OK’ and ‘OK’

No comments:

Post a Comment