我正在尝试在Rmarkdown中将表格编织为html输出。在RStudio中运行打印表块时,确实在“查看器”选项卡中获得了所需的输出格式:
但是,当我尝试将整个代码编织为html时,表格似乎在html文档中丢失了其格式:
我用来呈现这些html输出的代码:
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r, echo=FALSE, warning=FALSE, message=FALSE}
#run study
library(knitr)
library(broom)
library(kableExtra)
source("Load Base.R")
```
## FX Performance
```{r, echo=FALSE, results='asis'}
source("functions/functions.R")
temp<-cria_table(df=df.xts.rets, datas = c("2019-10-21","2019-10-01","2019-01-04", "2018-10-25"), row.tablenames = c("WtD", "MtD", "YtD", "12M"),caption="FX Performance as deviation (in %) to benchmark")
kable(temp[-1,],digits = 1,caption = "FX Performance as deviation (in %) to benchmark") %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
```
临时数据帧是一个简单的数据帧:
x<-sample(0:10, 13, replace = T)
y<-sample(0:10, 13, replace = T)
z<-sample(0:10, 13, replace = T)
temp2<-data.frame(cbind(x,y,z))
temp2<-t(temp2)
temp2<-as.data.frame(temp2)
rownames(temp2)<-c("MtD", "YtD", "12M")
names(temp2)<-c("BRL", "MXN", "COP", "PEN", "CLP", "TRY", "ZAR", "RUB", "IDR", "INR", "SGD", "CNH",
"KRW")
临时结构:
dput(temp)
structure(c(NA, 0.245944762916706, -0.894156351362008, 3.08653725521899,
NA, 0.498928791459474, 2.18942517241514, 5.89628231017694, NA,
0.65225368445716, -3.92645080384256, -6.16331871130317, NA, 0.121208248520244,
0.735245304879228, -0.403569989918617, NA, 0.0319232052804264,
1.19548773782774, 0.418607196177323, NA, 1.17741658565871, 3.09916586536103,
5.1411087783602, NA, 0.29199277703813, -4.26010006701491, -6.85199909276568,
NA, -0.446468482414186, 0.0407432119243767, -2.48418064300502,
NA, -1.14967013429852, 2.14931978994899, 1.63392653902903, NA,
-1.00935707767996, 2.42923572611407, 4.17436117595411, NA, -0.550796158031552,
-0.22678585243624, -0.913622930913149, NA, -0.715336967669677,
0.351449936516834, -0.544645694784129, NA, -0.4431607587566,
-1.17144079153269, -1.13960550555942), .Dim = c(4L, 13L), .Dimnames = list(
c("WtD", "MtD", "YtD", "12M"), c("BRL", "MXN", "COP", "PEN",
"CLP", "TRY", "ZAR", "RUB", "IDR", "INR", "SGD", "CNH", "KRW"
)))