So far as I know, xtable
only supports HTML and LaTeX formats (with LaTeX being the default). If you're rendering your document to a Word file, you need to pass your tables in markdown format. As far as options for what to do now, here are a few you can consider (presented as code suitable for your markdown document):
If knitting to a Word document:
---
title: "Sample Document"
output: word_document
---
```{r}
groupGrundALL <-
structure(list(Retouren.Grund = structure(c(5L, 2L, 1L, 3L, 4L,
6L, 7L), .Label = c("Abgelaufene Ware", "andere", "beschadigte Ware",
"Falschlieferung", "Fehlbestellung", "nicht abgeholt", "weggezogen"
), class = "factor"), Wert = c(685395, 237581, 129780, 37417,
9943, 1471, 25), Menge = c(11469, 4354, 3522, 729, 280, 21, 1
), Anzahl = c(222, 179, 1077, 143, 14, 11, 1)), .Names = c("Retouren.Grund",
"Wert", "Menge", "Anzahl"), row.names = c(NA, -7L), class = "data.frame")
```
## `knitr::kable`
```{r, echo=FALSE, message=FALSE, results='asis'}
knitr::kable(groupGrundALL, format = "markdown")
```
## `pixiedust`
For markdown tables, `pixiedust` is an extended wrapper for `knitr::kable` that allows you to do some additional formatting without having to preprocess data.
```{r, warning = FALSE}
library(pixiedust)
dust(groupGrundALL) %>%
sprinkle_print_method("markdown")
```
If you're comfortable installing packages from GitHub, you can also use the Grmd
package (devtools::install_github("gforge/Grmd")
) and knit to a docx_document
, which allows you to use the HTML output from xtable
, kable
, and pixiedust
. This means you can also have all the customizations of xtable
and pixiedust
available to you. When the document is completed, it is saved as an HTML file, so you can either right click and open as a word document, or change the extension to .docx
---
title: "Sample Document 2"
output: Grmd::docx_document
---
```{r}
groupGrundALL <-
structure(list(Retouren.Grund = structure(c(5L, 2L, 1L, 3L, 4L,
6L, 7L), .Label = c("Abgelaufene Ware", "andere", "beschadigte Ware",
"Falschlieferung", "Fehlbestellung", "nicht abgeholt", "weggezogen"
), class = "factor"), Wert = c(685395, 237581, 129780, 37417,
9943, 1471, 25), Menge = c(11469, 4354, 3522, 729, 280, 21, 1
), Anzahl = c(222, 179, 1077, 143, 14, 11, 1)), .Names = c("Retouren.Grund",
"Wert", "Menge", "Anzahl"), row.names = c(NA, -7L), class = "data.frame")
```
## `xtable` with HTML
```{r, echo=FALSE, message=FALSE, results='asis'}
library(xtable)
print(xtable(groupGrundALL), type = "html")
```
## `knitr::kable`
```{r, echo=FALSE, message=FALSE, results='asis'}
knitr::kable(groupGrundALL, format = "html")
```
## `pixiedust` with HTML
```{r, warning = FALSE}
library(pixiedust)
dust(groupGrundALL) %>%
sprinkle_print_method("html")
```
I have a strong bias for pixiedust
(obviously), but knitr::kable
is probably the fastest way to deal with simple markdown tables that don't need much customization.