I'm not sure I understand how exactly you're using for the aforementioned filter here.
((df1[i, "conditions"]) == "L")&
(df1[i, "work_location"] == df2[j, "Base.Country"])&
else if ((df1[i, "conditions"]) == "E""] then [(df1[i, "work_location"] == df2[j, "work_location])
Are you looking for something like the following? (...'s are the other filters)
... &
(((df1[i, "conditions"] == "L") & (df1[i, "work_location"] == df2[j, "Base.Country"])) | ((df1[i, "conditions"] == "E") & (df1[i, "work_location"] == "IND"))) &
...
If so, you can check this code.
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#> date
df1 <- data.frame(Job.cat = c(2L, 3L, 4L, 5L, 6L),
skill = as.factor(c("Art", "science", "maths", "maths", "sciencce")),
conditions = as.factor(c("L", "E", "L", "L", "L")),
work_location = as.factor(c("IND", "NZ", "CHI", "SWT", "IND")),
Date.created = as.factor(c("1/30/2016", "2/27/2017", "3/20/2018", "4/22/2017", "5/26/2018")))
df2 <- data.frame(Job.cat = c(2L, 3L, 4L, 5L, 3L, 2L, 3L, 3L, 5L, 5L, 5L),
Base.Country = as.factor(c("IND", "NZ", "NZ", "SWT", "IND", "IND", "IND", "IND", "SWT", "SWT", "SWT")),
Date.Available = as.factor(c("1/30/2016", "7/22/2017", "10/30/2018", "12/26/2017", "6/25/2016", "2/21/2016", "12/21/2015", "10/21/2015", "1/22/2017", "7/22/2017", "11/22/2016")),
skill = as.factor(c("Art", "science", "maths", "maths", "sciencce", "maths", "maths", "sciencce", "maths", "maths", "sciencce")))
df1$Date.created <- mdy(df1$Date.created)
df2$Date.Available <- mdy(df2$Date.Available)
# To view the lesser and greater 6 month range
df1$lessmonth <- as.Date(df1$Date.created) %m-% months(6)
df1$greatmonth <- as.Date(df1$Date.created) %m+% months(6)
for (i in 1:nrow(df1)){
count <- 0
for (j in 1:nrow(df2)){
if((df1[i, "skill"] == df2[j, "skill"])&
(df1[i, "Job.cat"] == df2[j, "Job.cat"] | df1[i, "Job.cat"] +1 == df2[j, "Job.cat"])&
(((df1[i, "conditions"] == "L") & (df1[i, "work_location"] == df2[j, "Base.Country"])) | ((df1[i, "conditions"] == "E") & (df1[i, "work_location"] == "IND"))) &
(df2[j, "Date.Available"] >= df1[i, "lessmonth"] & df2[j, "Date.Available"] <= df1[i, "greatmonth"]))
count <- count + 1
}
print(count)
df1[i, "out"] <- count
}
#> [1] 1
#> [1] 0
#> [1] 0
#> [1] 2
#> [1] 0