【发布时间】:2017-01-06 23:50:24
【问题描述】:
您是否看到使用tidyr::gather 函数收集tibble 类的最新问题?现在 dplyr 在 data.frame 上使用简单的 select 或 rename 函数后返回 tibble 。
有没有办法解决这个问题,而不是将tibble 类更改为data.frame?
简单的例子如下
> library(tibble)
> library(tidyr)
>
> head(gather(iris, Species))
Species Species value
1 setosa Sepal.Length 5.1
2 setosa Sepal.Length 4.9
3 setosa Sepal.Length 4.7
4 setosa Sepal.Length 4.6
5 setosa Sepal.Length 5.0
6 setosa Sepal.Length 5.4
>
> head(gather(as_tibble(iris), Species))
Error: Each variable must have a unique name.
Problem variables: 'Species'
>
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS
locale:
[1] LC_CTYPE=pl_PL.UTF-8 LC_NUMERIC=C LC_TIME=pl_PL.UTF-8
[4] LC_COLLATE=pl_PL.UTF-8 LC_MONETARY=pl_PL.UTF-8 LC_MESSAGES=pl_PL.UTF-8
[7] LC_PAPER=pl_PL.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=pl_PL.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] tidyr_0.6.0 tibble_1.2
loaded via a namespace (and not attached):
[1] magrittr_1.5 assertthat_0.1 tools_3.3.1 Rcpp_0.12.6
【问题讨论】:
-
这很荒谬,因为gather 在 'tbl' 上和在 'data.frame' 上一样工作,但在 dplyr 的最新版本中,它不适用于具有相似语法的 'tibbles'。由于这种不兼容,我将不得不重写许多代码行
-
@Axeman,您可以发表您的评论并回答,请