我有3个数据框并尝试遍历每个类别以获得每周的总(总和)交易数据$金额。
这是我的伪代码:
for a given productIDCat$Category {
for a given weeklydate$weekid{
calculate sum(transactiondata$amount)
when transactiondata$date is between weeklydate$begindate
and weeklydate$enddate
Append sum to new column in weeklydate
as weeklydate$testamount}}
Repeat this process for each week for that given product.
以下是我的数据框:
productIDCat
itemNo Category
1 Shoes
2 Shirts
3 Panties
4 Shoes
5 Shirts
6 Panties
transactiondata
amount date itemNo
12 2014-07-23 1
33 2014-07-29 1
6 2014-08-05 2
21 2014-08-06 2
23 2014-08-19 3
32 2014-08-27 3
weeklydate
weekid begindate enddate
1 2014-07-21 2014-07-25
2 2014-07-28 2014-08-01
3 2014-08-04 2014-08-08
4 2014-08-11 2014-08-15
5 2014-08-18 2014-08-22
6 2014-08-25 2014-08-29