Unable to collect Tibet in R

Have you seen a new problem with compiling a class tibbleusing tidyr::gatherfunciton? Now dplyrreturns tibbleafter using a simple function selector renameon data.frame.

Is there a way around this instead of changing the class tibbleto data.frame?

A simple example below

> 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   
+4
source share
1 answer

The problem is not necessarily with tibble. It does a safe (and possibly very restrictive) thing that does not allow duplicate column names.

, gather . key value , :

gather(iris, key, value, -Species)
+4

Source: https://habr.com/ru/post/1653017/


All Articles