Skip to content

augment method for kmeans not working #609

@IndrajeetPatil

Description

@IndrajeetPatil
# setup
set.seed(123)
d <- data.frame(x = runif(100), y = runif(100))

# kmeans
clus <- stats::kmeans(x = d, centers = 5)

# getting cluster assignment as a column
broom::augment(x = clus, data = d)
#> Error in x$cluster: $ operator is invalid for atomic vectors

Here is the traceback-

> traceback()
14: factor(x$cluster)
13: mutate_impl(.data, dots, caller_env())
12: mutate.tbl_df(., .cluster = factor(x$cluster))
11: mutate(., .cluster = factor(x$cluster))
10: function_list[[k]](value)
9: withVisible(function_list[[k]](value))
8: freduce(value, `_function_list`)
7: `_fseq`(`_lhs`)
6: eval(quote(`_fseq`(`_lhs`)), env, env)
5: eval(quote(`_fseq`(`_lhs`)), env, env)
4: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
3: fix_data_frame(data, newcol = ".rownames") %>% mutate(.cluster = factor(x$cluster))
2: augment.kmeans(x = clus, data = d)
1: broom::augment(x = clus, data = d)

Session information

options(width = 200)
sessioninfo::session_info(include_base = TRUE)
#> - Session info ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#>  setting  value                                             
#>  version  R Under development (unstable) (2018-11-30 r75724)
#>  os       Windows 10 x64                                    
#>  system   x86_64, mingw32                                   
#>  ui       RTerm                                             
#>  language (EN)                                              
#>  collate  English_United States.1252                        
#>  ctype    English_United States.1252                        
#>  tz       America/New_York                                  
#>  date     2019-02-24                                        
#> 
#> - Packages -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#>  ! package     * version    date       lib source                            
#>    assertthat    0.2.0      2017-04-11 [1] CRAN (R 3.5.1)                    
#>    base        * 3.6.0      2018-12-01 [?] local                             
#>    cli           1.0.1.9000 2019-01-20 [1] Github (r-lib/cli@94e2fc5)        
#>  P compiler      3.6.0      2018-12-01 [2] local                             
#>    crayon        1.3.4      2017-09-16 [1] CRAN (R 3.5.1)                    
#>  P datasets    * 3.6.0      2018-12-01 [2] local                             
#>    digest        0.6.18     2018-10-10 [1] CRAN (R 3.5.1)                    
#>    evaluate      0.13       2019-02-12 [1] CRAN (R 3.6.0)                    
#>  P graphics    * 3.6.0      2018-12-01 [2] local                             
#>  P grDevices   * 3.6.0      2018-12-01 [2] local                             
#>    highr         0.7        2018-06-09 [1] CRAN (R 3.5.1)                    
#>    htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.5.1)                    
#>    knitr         1.21       2018-12-10 [1] CRAN (R 3.6.0)                    
#>    magrittr      1.5        2014-11-22 [1] CRAN (R 3.5.1)                    
#>  P methods     * 3.6.0      2018-12-01 [2] local                             
#>    Rcpp          1.0.0      2018-11-07 [1] CRAN (R 3.6.0)                    
#>    rmarkdown     1.11.6     2019-02-14 [1] Github (rstudio/rmarkdown@bbd0786)
#>    sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                    
#>  P stats       * 3.6.0      2018-12-01 [2] local                             
#>    stringi       1.3.1      2019-02-13 [1] CRAN (R 3.6.0)                    
#>    stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.0)                    
#>  P tools         3.6.0      2018-12-01 [2] local                             
#>  P utils       * 3.6.0      2018-12-01 [2] local                             
#>    withr         2.1.2      2018-03-15 [1] CRAN (R 3.5.1)                    
#>    xfun          0.5        2019-02-20 [1] CRAN (R 3.6.0)                    
#>    yaml          2.2.0      2018-07-25 [1] CRAN (R 3.5.1)                    
#> 
#> [1] C:/Users/inp099/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-devel/library
#> 
#>  P -- Loaded and on-disk path mismatch.

Created on 2019-02-24 by the reprex package (v0.2.1.9000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    beginner-friendlybugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions