-
Notifications
You must be signed in to change notification settings - Fork 10
Description
tmp_store_test before
tmp_store_test
store_code sale_date day_of_week_ori payment_amount is_vacation
32 100000022 2019-10-14 1 10769.87 0
39 100000022 2019-10-21 1 10327.14 0
46 100000022 2019-10-28 1 9834.03 0
53 100000022 2019-11-04 1 8654.33 0
60 100000022 2019-11-11 1 10855.01 0
69 100000022 2019-07-22 1 12737.00 1
76 100000022 2019-07-29 1 13652.91 1
83 100000022 2019-08-05 1 11824.64 1
90 100000022 2019-08-12 1 12026.49 1
97 100000022 2019-08-19 1 12490.36 1
104 100000022 2019-08-26 1 12776.02 1
tmp_store_test <- tmp_store_test[with(tmp_store_test,order(store_code,is_vacation,day_of_week_ori)),]
tmp_store_test <- slide(tmp_store_test, Var="payment_amount", TimeVar="sale_date", GroupVar=c("store_code",'is_vacation','day_of_week_ori'), NewVar="Data_lagged_7_pay",slideBy = -1, keepInvalid = FALSE, reminder = FALSE)
tmp_store_test after
tmp_store_test
store_code sale_date day_of_week_ori payment_amount is_vacation Data_lagged_7_pay
1 100000022 2019-10-14 1 10769.87 0 NA
2 100000022 2019-10-21 1 10327.14 0 10769.87
3 100000022 2019-10-28 1 9834.03 0 10327.14
4 100000022 2019-11-04 1 8654.33 0 9834.03
5 100000022 2019-11-11 1 10855.01 0 8654.33
6 100000022 2019-07-22 1 12737.00 1 10855.01
7 100000022 2019-07-29 1 13652.91 1 12737.00
8 100000022 2019-08-05 1 11824.64 1 13652.91
9 100000022 2019-08-12 1 12026.49 1 11824.64
10 100000022 2019-08-19 1 12490.36 1 12026.49
11 100000022 2019-08-26 1 12776.02 1 12490.36
The result is not true ,since is_vacation is in the GroupVar of slide function, the first value of is_vacation=1 should be NA. But the result use the last value of is_vacation=0.
6 100000022 2019-07-22 1 12737.00 1 10855.01(should be NA)
This problem is confusing. If the GroupVar only have (store_code,day_of_week_ori),this fuction is valid only for dataframe with one store. If the store number>1, the same thing goes wrong!
Thanks a lot.