rsquaredacademy / rfm

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

Manipulate rfm_table_order output object #64

Closed DavidGarciaEstaun closed 4 years ago

DavidGarciaEstaun commented 4 years ago

Hi,

I need to manipulate frequency_score, because I do not want to split by quintiles because I don't have an homogeneus distribution. The problem is that if I change the dataframe I can't use the plotting functions because my object don't have the correct class: "rfm_table_order" "tibble" "data.frame"

rfmData <- rfm_table_order(data, email, date, revenue, today()-2, 5,5,5)
rfmDf   <- rfmData$rfm %>% mutate(frequency_score=case_when(transaction_count==1 ~ 1,
                                                            transaction_count==2 ~ 2,
                                                            transaction_count==3 ~ 3,
                                                            transaction_count==4 ~ 4,
                                                            transaction_count>4 ~ 5))

How can I modify the rfm_table_order output object to mantaining the correct class?

I hope that I have explained the problem well. Thanks in advance.

aravindhebbali commented 4 years ago

If I am correct, you want to manually specify the threshold for the frequency score. I have started working on that feature #58.

For generating the plots, can you check if the below code works

rfmData$rfm %<>% mutate(frequency_score=case_when(transaction_count==1 ~ 1,
                                                            transaction_count==2 ~ 2,
                                                            transaction_count==3 ~ 3,
                                                            transaction_count==4 ~ 4,
                                                            transaction_count>4 ~ 5))

Check the class of rfmData after running the above code and let me know. In case it does not work, I will make changes to the plot functions so that they can be generated even with modified data.

DavidGarciaEstaun commented 4 years ago

Hi Aravind,

First of all, thanks for your quickly answer. This is exactly that I need, set an specific threshold for the frequency score based on the transaction_count but not in quintiles or NTiles. My problem is that in my case if I do it with quintiles I have all customers in frequency_score= 1 or =5.

Before the opening of this issue I tried the code that you indicated and the result was:

Error in `$<-.data.frame`(`*tmp*`, rfm, value = list(customer_id = c("0311hear@gmail.com",  : 
  replacement has 3903 rows, data has 0

The class is still the same but due to the previous error I can't modify the object :

> class(rfmData)
[1] "rfm_table_order" "tibble"          "data.frame"     

Thanks!

aravindhebbali commented 4 years ago

Hi @DavidGarciaEstaun I will add a few custom functions to enable modification of the output from rfm_table_order() as well as generation of plots by Friday and will keep you posted.

DavidGarciaEstaun commented 4 years ago

Hi @aravindhebbali , This is perfect. At the moment I am modifying and plotting manually but I think that this is a good improvement for the package.

Thank you!