1
$\begingroup$
custid  tot_prod       tot_rev          Last_tran   total_trans

1 1002 13 1465.25 11/23/2011 4 2 1003 2 353.25 1/1/2011 1 3 1004 12 2466.5 11/25/2011 12

Above is the Retail dataset of customer. I need to calculate recency(a new attribute when the customer is last seen) from last transaction(last_tran) in terms of month.i.e. he purchased in last 3 months or last 6 months or may be one year in R. please suggest.

$\endgroup$

1 Answer 1

2
$\begingroup$

Try this

as.POSIXct(Sys.Date(), format= "%Y-%m-%d", tz="UCT") - as.POSIXct("11/25/2011", format = "%m/%d/%Y",tz="UCT")

More vectorized operation in your situation

as.POSIXct(Sys.Date(), format= "%Y-%m-%d", tz="UCT") - as.POSIXct(Last_tran, format = "%m/%d/%Y",tz="UCT")
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.