RFM Analysis on Retail data transactiom

i am getting error while doing a command
df_RFM <- abc %>%
group_by(customer_id) %>%
summarise(recency=as.numeric(analysis_date-max(trans_date)),
frequency =n_distinct(customer_id), monetary=sum(trans_amount))
and the output i am getting this

  • df_RFM <- abc %>%
    Error: unexpected symbol in:
    " mutate(customer_id=as.factor(customer_id), trans_date=as.Date(trans_date)
    df_RFM"

group_by(customer_id) %>%

  • summarise(recency=as.numeric(analysis_date-max(trans_date)),
  •       frequency =n_distinct(customer_id), monetary=sum(trans_amount))        
    

Error in group_by(customer_id) : object 'customer_id' not found

df_RFM <- abc %>%

  • group_by(customer_id) %>%
  • summarise(recency=as.numeric(analysis_date-max(trans_date)),
  •       frequency =n_distinct(customer_id), monetary=sum(trans_amount))        
    

Error: object 'trans_amount' not found
In addition: There were 50 or more warnings (use warnings() to see the first 50)

summary(abc)
customer_id trans_date tran_amount
Length:125000 Min. :2011-05-16 00:00:00 Min. : 10.00
Class :character 1st Qu.:2012-04-29 00:00:00 1st Qu.: 47.00
Mode :character Median :2013-04-14 00:00:00 Median : 65.00
Mean :2013-04-13 12:01:16 Mean : 64.99
3rd Qu.:2014-03-28 00:00:00 3rd Qu.: 83.00
Max. :2015-03-16 00:00:00 Max. :105.00

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.