我使用starting将R集成到LaTeX中,其中应打印以零开头的小数,而不应打印零。例如
0.05 => .05
0.5 => .5
1.5 => 1.5有没有一种简单的方法可以让knitr做到这一点?
发布于 2016-08-31 18:18:08
当您的输出是数值并且介于-1和1之间时,您可以重新定义内联钩子以删除0。
---
output: pdf_document
---
```{r echo=FALSE}库(Knitr)
Knit_hooks$set(内联=
函数(x) {
if (is.numeric(x)) { x = round(x, getOption("digits")) if (x < 1 & x > -1) { x = sub("0\\.","\\.",as.character(x)) } } paste(as.character(x), collapse = ", ") })
Sepal and Petal lengths (r = `r cor(iris$Sepal.Length, iris$Petal.Length)`) ;
Sepal length and width (r = `r cor(iris$Sepal.Length, iris$Sepal.Width)`)https://stackoverflow.com/questions/39246502
复制相似问题