我正在使用Rmarkdown并希望使用knitr :: kable()显示表格。
我有两个应该输出表的代码块。事情是一个工作,一个没有。两者都试图输出数据帧。
这个有效:
### Payment method comparison
How much invoice and account purchases grew for the switching merchants.
```{r, include = TRUE, echo = FALSE}
leg_growth <- skco.growth(groups = c('Purchase_Country', 'Paymethod'), unit = 'Volume') %>%
select(Purchase_Country, Paymethod, relative_growth) %>%
filter(!is.na(relative_growth),
Paymethod != 'Credit card') %>%
mutate(relative_growth = to.percent(relative_growth - 1))
leg_growth%>%knitr::kable()
```
这个没有:
###Number of Brands
This is a similar scatter plot to the previous one but shows merchants grouped by the Industry Segment.
Number of switching merchants included in the sample.
```{r, include = TRUE, echo = FALSE}
a<-switching_data %>%
group_by(Purchase_Country) %>%
summarize(nr_brands = n_distinct(Brand_id))
a%>%knitr::kable()
```
我不确定两者之间有什么区别,但是在Rmarkdown中运行代码并没有向我显示任何内容。
数据结构:
> str(a)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 4 obs. of 2 variables:
$ Purchase_Country: chr "d" "f" "n" "s"
$ nr : int 24 94 140 440
> str(leg_growth)
'data.frame': 8 obs. of 3 variables:
$ Purchase_Country: chr "d" "d" "f" "f" ...
$ method : Factor w/ 9 levels "A","C",..: 1 7 1 7 1 7 1 7
$ growth : chr "55%" "-3%" "18%" "91%" ...