how to calculate recency(RFM) from a given date attribute in R 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.
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")