如何将向量强制转换为 tibble?

how to coerce a vector into a tibble?

将向量强制转换为 tibble 的 'right' 方法是什么?我正在尝试使用 tidyverse,但它似乎有一个漏洞。

假设我有一个向量,我想把它变成一行的小标题(参见一列)。根据 the documentation for tibble 我应该可以使用 as_tibble_row() (参见 as_tibble_col()as_tibble_column() *)。但是,当我尝试调用这些函数时,它们似乎并不存在。我已经安装并导入了 tidyversev3.0.1(其中包含 tibble v2.1.3)。

> as_tibble_row(c(a = 1, b = 2))
Error in as_tibble_row(c(a = 1, b = 2)) : 
  could not find function "as_tibble_row"
> as_tibble_col(c(a = 1, b = 2))
Error in as_tibble_col(c(a = 1, b = 2)) : 
  could not find function "as_tibble_col"
> as_tibble_column(c(a = 1, b = 2))
Error in as_tibble_column(c(a = 1, b = 2)) : 
  could not find function "as_tibble_column"

同样??as_tibble_row??as_tibble_col??as_tibble_column找不到结果。

当我尝试简单的 as_tibble() 时,它给了我一个 tibble 列,但我收到了警告

> as_tibble(c(a = 1, b = 2))
# A tibble: 2 x 1
  value
  <dbl>
1     1
2     2
Warning message:
Calling `as_tibble()` on a vector is discouraged, 
because the behavior is likely to change in the future. 
Use `tibble::enframe(name = NULL)` instead.

按照建议使用 enframe() 给出列的预期结果:

> tibble::enframe(c(a = 1, b = 2))
# A tibble: 2 x 2
  name  value
  <chr> <dbl>
1 a         1
2 b         2

但我仍然不知道如何将矢量强制转换为一行。我错过了什么(也许文档需要更新,因为它似乎引用了这些似乎不存在的功能)?


*文档中列版本的描述函数在描述中将其称为 as_tibble_column(),但在其他地方称为 as_tibble_col()...

我觉得

as_tibble(t(c(a = 1, b = 2)))

是您要查找的内容(尽管您实际上并未在此处指定确切的所需输出)。

> as_tibble(t(c(a = 1, b = 2)))
# A tibble: 1 x 2
      a     b
  <dbl> <dbl>
1     1     2

您指向的文档是指软件包的 3.0.1 版(您说您使用的是 2.1.3):

> as_tibble_col(c(a = 1, b = 2))
# A tibble: 2 x 1
  value
  <dbl>
1     1
2     2
> as_tibble_row(c(a = 1, b = 2))
# A tibble: 1 x 2
      a     b
  <dbl> <dbl>
1     1     2

NEWS file说这些功能是3.0.0版本新增的。