rsquaredacademy / rfm

Tools for Customer Segmentation using RFM Analysis
https://rfm.rsquaredacademy.com/
Other
59 stars 28 forks source link

Error in custom bins in function rfm_table_order() #75

Closed gfagherazzi closed 3 years ago

gfagherazzi commented 3 years ago

Hi Aravind, I'm trying the custom definition of bins as reported in your example:

result <- rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date,

  • recency_bins = c(115, 181, 297, 482), frequency_bins = c(4, 5, 6, 8),
  • monetary_bins = c(256, 382, 506, 666))

The problem I have is this> Warning messages: 1: In seq_len(.) : first element used of 'length.out' argument 2: In seq_len(recency_bins) : first element used of 'length.out' argument 3: In seq_len(.) : first element used of 'length.out' argument 4: In seq_len(frequency_bins) : first element used of 'length.out' argument 5: In seq_len(.) : first element used of 'length.out' argument 6: In seq_len(monetary_bins) : first element used of 'length.out' argument

And the result of

result$rfm Is that I have a N/A in the frequency_score column

aravindhebbali commented 3 years ago

Hi @gfagherazzi , I am not able to reproduce the warnings. Can you share the session info?

# load libraries
library(rfm)

# analysis date
analysis_date <- lubridate::as_date('2006-12-31')

# custom threshold
rfm_table_order(rfm_data_orders, 
                customer_id, 
                order_date, 
                revenue, 
                analysis_date, 
                recency_bins   = c(115, 181, 297, 482), 
                frequency_bins = c(4, 5, 6, 8), 
                monetary_bins  = c(256, 382, 506, 666))
#> # A tibble: 995 x 9
#>    customer_id date_most_recent recency_days transaction_cou~ amount
#>    <chr>       <date>                  <dbl>            <dbl>  <dbl>
#>  1 Abbey O'Re~ 2006-06-09                205                6    472
#>  2 Add Senger  2006-08-13                140                3    340
#>  3 Aden Lesch~ 2006-06-20                194                4    405
#>  4 Admiral Se~ 2006-08-21                132                5    448
#>  5 Agness O'K~ 2006-10-02                 90                9    843
#>  6 Aileen Bar~ 2006-10-08                 84                9    763
#>  7 Ailene Her~ 2006-03-25                281                8    699
#>  8 Aiyanna Br~ 2006-04-29                246                4    157
#>  9 Ala Schmid~ 2006-01-16                349                3    363
#> 10 Alannah Bo~ 2005-04-21                619                4    196
#> # ... with 985 more rows, and 4 more variables: recency_score <int>,
#> #   frequency_score <int>, monetary_score <int>, rfm_score <dbl>

# session info
sessionInfo()
#> R version 4.0.4 (2021-02-15)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19042)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_India.1252  LC_CTYPE=C                    
#> [3] LC_MONETARY=English_India.1252 LC_NUMERIC=C                  
#> [5] LC_TIME=English_India.1252    
#> system code page: 1252
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] rfm_0.2.1.9000
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.5        rstudioapi_0.13   knitr_1.27        magrittr_2.0.1   
#>  [5] tidyselect_1.1.0  R6_2.5.0          rlang_0.4.10      fansi_0.4.1      
#>  [9] stringr_1.4.0     highr_0.8         dplyr_1.0.2       tools_4.0.4      
#> [13] xfun_0.20         utf8_1.1.4        cli_2.4.0         htmltools_0.5.0  
#> [17] ellipsis_0.3.1    yaml_2.2.1        digest_0.6.25     tibble_3.0.4     
#> [21] lifecycle_0.2.0   crayon_1.3.4      purrr_0.3.4       vctrs_0.3.5      
#> [25] glue_1.4.2        evaluate_0.14     rmarkdown_2.6     stringi_1.5.3    
#> [29] compiler_4.0.4    pillar_1.4.4      generics_0.1.0    lubridate_1.7.9.2
#> [33] pkgconfig_2.0.3

Created on 2021-05-19 by the reprex package (v0.3.0)

gfagherazzi commented 3 years ago

Hi @aravindhebbali , hope this can help. Thank you!

image

gfagherazzi commented 3 years ago

Hi @aravindhebbali , got it! I updated the RFM package version and now it works fine. Thank you