簡體   English   中英

如何在 R 的 sapply 中使用 kable

[英]How to use kable inside sapply in R

我的目標是同時將多個列制成表格,我使用了以下內容:

sapply(iris[1:4], table)

接下來我嘗試使用 kable 格式化 output,但我一直收到錯誤:

sapply(iris[1:4], knitr::kable(table))
Error in seq_len(m) : argument must be coercible to non-negative integer

所以我想知道是否可以在 sapply 中使用 kable。

謝謝你。

您是否嘗試使用 purrr package 中的 map() function?

此 function 將任何 function 應用於列表的每個元素(這里,您有一個數據框,因此它將應用 function 到每一列)

就個人而言,我這樣做:

map(iris[1:4], function(.x){

        .x %>% knitr::kable() 
        #You can include any styling options after
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM