Skip to content

Error in unique.default(x, nmax = nmax): unique() applies only to vectors #5392

@XiangyunHuang

Description

@XiangyunHuang
do.call("rbind.data.frame", lapply(base::split(x = iris, ~Species), head))
#>               Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
#> setosa.1               5.1         3.5          1.4         0.2     setosa
#> setosa.2               4.9         3.0          1.4         0.2     setosa
#> setosa.3               4.7         3.2          1.3         0.2     setosa
#> setosa.4               4.6         3.1          1.5         0.2     setosa
#> setosa.5               5.0         3.6          1.4         0.2     setosa
#> setosa.6               5.4         3.9          1.7         0.4     setosa
#> versicolor.51          7.0         3.2          4.7         1.4 versicolor
#> versicolor.52          6.4         3.2          4.5         1.5 versicolor
#> versicolor.53          6.9         3.1          4.9         1.5 versicolor
#> versicolor.54          5.5         2.3          4.0         1.3 versicolor
#> versicolor.55          6.5         2.8          4.6         1.5 versicolor
#> versicolor.56          5.7         2.8          4.5         1.3 versicolor
#> virginica.101          6.3         3.3          6.0         2.5  virginica
#> virginica.102          5.8         2.7          5.1         1.9  virginica
#> virginica.103          7.1         3.0          5.9         2.1  virginica
#> virginica.104          6.3         2.9          5.6         1.8  virginica
#> virginica.105          6.5         3.0          5.8         2.2  virginica
#> virginica.106          7.6         3.0          6.6         2.1  virginica

library(data.table)

iris <- as.data.table(iris)

do.call("rbind.data.frame", lapply(base::split(x = iris, ~Species), head))
#> Error in unique.default(x, nmax = nmax): unique() applies only to vectors

sessionInfo()
#> R version 4.2.0 (2022-04-22)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Big Sur/Monterey 10.16
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] data.table_1.14.2
#> 
#> loaded via a namespace (and not attached):
#>  [1] rstudioapi_0.13   knitr_1.39        magrittr_2.0.3    R.cache_0.15.0   
#>  [5] rlang_1.0.2       fastmap_1.1.0     fansi_1.0.3       stringr_1.4.0    
#>  [9] styler_1.7.0      highr_0.9         tools_4.2.0       xfun_0.31        
#> [13] R.oo_1.24.0       utf8_1.2.2        cli_3.3.0         withr_2.5.0      
#> [17] htmltools_0.5.2   ellipsis_0.3.2    yaml_2.3.5        digest_0.6.29    
#> [21] tibble_3.1.7      lifecycle_1.0.1   crayon_1.5.1      purrr_0.3.4      
#> [25] R.utils_2.11.0    vctrs_0.4.1       fs_1.5.2          glue_1.6.2       
#> [29] evaluate_0.15     rmarkdown_2.14    reprex_2.0.1      stringi_1.7.6    
#> [33] compiler_4.2.0    pillar_1.7.0      R.methodsS3_1.8.1 pkgconfig_2.0.3

Created on 2022-05-24 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions