【问题标题】:How do I resize an R output table in markddown?如何在 Markdown 中调整 R 输出表的大小?
【发布时间】:2021-09-26 04:03:46
【问题描述】:

我一直在寻找时间在降价时调整表格的大小,以免损坏。我想过减少源或强制它不中断,但我该怎么做呢?我只找到了使用 kable 或 kableextra 的解决方案,但是我想要默认样式。我把数据留在了网址里。

data

【问题讨论】:

    标签: r yaml r-markdown markdown knitr


    【解决方案1】:

    我们可以更改options 中的width。检查当前的width 并进行更改

    > head(cbind(iris, iris, iris))
      Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length Sepal.Width Petal.Length
    1          5.1         3.5          1.4         0.2  setosa          5.1         3.5          1.4         0.2  setosa          5.1         3.5          1.4
    2          4.9         3.0          1.4         0.2  setosa          4.9         3.0          1.4         0.2  setosa          4.9         3.0          1.4
    3          4.7         3.2          1.3         0.2  setosa          4.7         3.2          1.3         0.2  setosa          4.7         3.2          1.3
    4          4.6         3.1          1.5         0.2  setosa          4.6         3.1          1.5         0.2  setosa          4.6         3.1          1.5
    5          5.0         3.6          1.4         0.2  setosa          5.0         3.6          1.4         0.2  setosa          5.0         3.6          1.4
    6          5.4         3.9          1.7         0.4  setosa          5.4         3.9          1.7         0.4  setosa          5.4         3.9          1.7
      Petal.Width Species
    1         0.2  setosa
    2         0.2  setosa
    3         0.2  setosa
    4         0.2  setosa
    5         0.2  setosa
    6         0.4  setosa
    > op <- options()
    > options()$width # check the current width
    [1] 167
    > options(width = 300) # change the width and now do the print again
    > head(cbind(iris, iris, iris))
      Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length Sepal.Width Petal.Length Petal.Width Species
    1          5.1         3.5          1.4         0.2  setosa          5.1         3.5          1.4         0.2  setosa          5.1         3.5          1.4         0.2  setosa
    2          4.9         3.0          1.4         0.2  setosa          4.9         3.0          1.4         0.2  setosa          4.9         3.0          1.4         0.2  setosa
    3          4.7         3.2          1.3         0.2  setosa          4.7         3.2          1.3         0.2  setosa          4.7         3.2          1.3         0.2  setosa
    4          4.6         3.1          1.5         0.2  setosa          4.6         3.1          1.5         0.2  setosa          4.6         3.1          1.5         0.2  setosa
    5          5.0         3.6          1.4         0.2  setosa          5.0         3.6          1.4         0.2  setosa          5.0         3.6          1.4         0.2  setosa
    6          5.4         3.9          1.7         0.4  setosa          5.4         3.9          1.7         0.4  setosa          5.4         3.9          1.7         0.4  setosa
    

    完成后,再次重置options

    > options(op)
    > options()$width
    [1] 167
    

    【讨论】:

    • 谢谢@akrun,太棒了!我没想过修改选项=/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-01
    • 2020-04-04
    • 2019-03-09
    • 2016-04-29
    • 1970-01-01
    • 2017-05-05
    相关资源
    最近更新 更多