0

我有多个表集(表集 1,表集 2,...),所以我想创建一个函数:

  1. 编织我的桌子(在 R 降价中)
  2. 并根据我正在使用的表格集自动更改表格标题

下面是我创建的函数,但是当我运行该函数时,它会返回给我:

  1. 一张桌子(我期望的)
  2. 一行[1] "1"(我不知道这是什么以及为什么函数返回此行)
    你能帮我解释一下那行以及如何删除它吗?

您可以使用以下代码进行复制

table.set1 <- rbind(c(3, 27),
                    c(33, 9))
rownames(table.set1) <- c("Studying", "Not-studying")
colnames(table.set1) <- c("Men", "Women")

myfunction <- function(mydata, mytext) {
            knitr::kable(mydata,
                        caption = glue::glue("Table set {print(mytext)}")
            )
}


> myfunction(mydata = table.set1, mytext = "1")
## [1] "1"
##
##
## Table set 1
##
## |             | Men| Women|
## |:------------|---:|-----:|
## |Studying     |   3|    27|
## |Not-studying |  33|     9|

> class(myfunction(mydata = table.set1, mytext = "1"))
## [1] "1"
## [1] "knitr_kable"
           
4

0 回答 0