对于R Markdown,如何显示R变量的矩阵

时间:2022-09-21 19:38:39

I have a rmd document where I have the following

我有一个rmd文档,我有以下内容

```{r code_block, echo=FALSE}
A = matrix(c(1,3,0,1),2,2)
B = matrix(c(5,3,1,4),2,2)
```

$$
\begin{bmatrix} 
1  & 0 \\ 
3 & 1 \\ 
\end{bmatrix}
*
\begin{bmatrix} 
5 & 1 \\ 
3 & 4 \\ 
\end{bmatrix}
$$

Now I would like to instead of hard coding the LaTeX part manually, I could use the matrix from the variables A and B instead. How could this be done?

现在我想手动硬编码LaTeX部件,而不是使用变量A和B中的矩阵。怎么可以这样做?

Thanks.

1 个解决方案

#1


0  

hello you can use library(printr) in a markdown block

您好,您可以在降价块中使用库(printr)

knitr::kable(A ,  caption = "matrix A")

from https://yihui.name/printr/

like this

```{r code_block, echo=FALSE}
A = matrix(c(1,3,0,1),2,2)
B = matrix(c(5,3,1,4),2,2)
knitr::kable(A ,  caption = "matrix A")
```

#1


0  

hello you can use library(printr) in a markdown block

您好,您可以在降价块中使用库(printr)

knitr::kable(A ,  caption = "matrix A")

from https://yihui.name/printr/

like this

```{r code_block, echo=FALSE}
A = matrix(c(1,3,0,1),2,2)
B = matrix(c(5,3,1,4),2,2)
knitr::kable(A ,  caption = "matrix A")
```