Как я могу исправить тип in_date в пакетах rfm? - PullRequest
0 голосов
/ 27 ноября 2018

Я использовал коммерческие данные.Детали RFM Инструменты для анализа RFM (последние, частотные и денежные). Но я не использовал данные в ссылке.Я просто хочу применить этот пакет.Хотя я исправил тип даты, я не могу его использовать.

#clensing data
> library(dplyr)
> data <- fread("RFMdata.csv")
> str(data)
Classes ‘data.table’ and 'data.frame':  541909 obs. of  8 variables:
 $ InvoiceNo  : chr  "536365" "536365" "536365" "536365" ...
 $ StockCode  : chr  "85123A" "71053" "84406B" "84029G" ...
 $ Description: chr  "WHITE HANGING HEART T-LIGHT HOLDER" "WHITE METAL 
LANTERN" "CREAM CUPID HEARTS COAT HANGER" "KNITTED UNION FLAG HOT WATER 
BOTTLE" ...
 $ Quantity   : int  6 6 8 6 6 2 6 6 6 32 ...
 $ InvoiceDate: chr  "12/1/2010 8:26" "12/1/2010 8:26" "12/1/2010 8:26"             
"12/1/2010 8:26" ...
 $ UnitPrice  : num  2.55 3.39 2.75 3.39 3.39 7.65 4.25 1.85 1.85 1.69 ...
 $ CustomerID : int  17850 17850 17850 17850 17850 17850 17850 17850 17850 
13047 ...
 $ Country    : chr  "United Kingdom" "United Kingdom" "United Kingdom" 
"United Kingdom" ...
 - attr(*, ".internal.selfref")=<externalptr> 

> data <- data %>% 
   mutate(InvoiceNo=as.factor(InvoiceNo), StockCode=as.factor(StockCode), 
     InvoiceDate=as.Date(InvoiceDate, '%m/%d/%Y %H:%M'), CustomerID=as.factor(CustomerID), 
     Country=as.factor(Country))
> data <- data %>% 
  mutate(total_dolar = Quantity*UnitPrice)

> str(data)
'data.frame':   541909 obs. of  8 variables:
 $ InvoiceNo  : Factor w/ 25900 levels "536365","536366",..: 1 1 1 1 1 1 1 2 
2 3 ...
 $ StockCode  : Factor w/ 4070 levels "10002","10080",..: 3538 2795 3045 
2986 2985 1663 801 1548 1547 3306 ...
 $ Description: chr  "WHITE HANGING HEART T-LIGHT HOLDER" "WHITE METAL 
LANTERN" "CREAM CUPID HEARTS COAT HANGER" "KNITTED UNION FLAG HOT WATER 
BOTTLE" ...
 $ Quantity   : int  6 6 8 6 6 2 6 6 6 32 ...
 $ InvoiceDate: Date, format: "2010-12-01" "2010-12-01" "2010-12-01" "2010- 
12-01" ...
 $ UnitPrice  : num  2.55 3.39 2.75 3.39 3.39 7.65 4.25 1.85 1.85 1.69 ...
 $ CustomerID : Factor w/ 4372 levels "12346","12347",..: 4049 4049 4049 
4049 4049 4049 4049 4049 4049 541 ...
 $ Country    : Factor w/ 38 levels "Australia","Austria",..: 36 36 36 36 36 
36 36 36 36 36 ...
 $ total_dolar: num  15.3 20.3 22 20.3 20.3 ...

#RFM act
> library(rfm)
> rfm_r <- rfm_table_order(data = data, customer_id = CustomerID, order_date = InvoiceDate, revenue = total_dolar)

Сообщение об ошибке «Дата», как я могу это исправить?

Error in mutate_impl(.data, dots) : 
  Evaluation error: can only subtract from "Date" objects.
...