that is how to run a condition for each row in the outer data frame for each row in the inner data frame) I have two data frames :
ToTest
Origin.State Dest.State Ship.Date Cost
1 IL NY 2015-03-25 10
2 IL NY 2015-03-25 10
3 IL NY 2015-03-24 10
4 IL NY 2015-03-23 10
5 IL NY 2015-03-18 10
6 PA NY 2015-04-29 10
7 PA NY 2015-04-29 10
8 PA NY 2015-04-27 10
9 PA NY 2015-04-24 10
10 PA NY 2015-03-01 10
11 IL TX 2015-05-18 10
12 IL TX 2015-05-18 10
13 IL TX 2015-05-14 10
14 IL TX 2015-05-12 10
15 IL TX 2015-05-13 10
TestShipmentGroup1
Origin.State Dest.State Ship.Date
1 IL NY 2015-03-25
2 IL NY 2015-03-24
3 IL NY 2015-03-23
4 IL NY 2015-03-18
5 PA NY 2015-04-29
6 PA NY 2015-04-27
7 PA NY 2015-04-24
8 PA NY 2015-03-01
9 IL TX 2015-05-18
10 IL TX 2015-05-14
11 IL TX 2015-05-12
12 IL TX 2015-05-13
I am trying to apply the conditions shown below to every row in the ToTest dataframe using each row of TestShipmentGroup1 dataframe at a time.
for (i in 1: nrow(TestShipmentGroup1))
{
TestShipmentGroup1%>%
select(Origin.State,Dest.State,Ship.Date)
ToTest%>%
select(Origin.State, Dest.State,Ship.Date,Cost) %>%
filter (((ToTest$Ship.Date >= (TestShipmentGroup1$Ship.Date-7))
& (ToTest$Ship.Date < TestShipmentGroup1$Ship.Date))
& (ToTest$Origin.State == TestShipmentGroup1$Origin.State)
& (ToTest$Dest.State == TestShipmentGroup1$Dest.State))}