Help on Looping

Thanks Woodward. I think i have to explain much more here.
The filters are based on one condition where Date_Created variables is always greater than equal to less than 6 months of the variable. So first we have to create a new variable called less6month which is derived from Date_Created.
e.g chk$lessmonth <- as.Date(chk$Date_Created, "%m/%d/%Y") %m-% months(6)
Objective of the problem - Create two new variables.
The first variable is Count

  1. Count - Count of all the rows in the datasets which satisfies the below condition. Where
    if(Location==location)&(department==department)& (grade==grade) & Date_Created >= Less than 6 month.
    My code should go through each and every row and see if all the filter conditions are satisfied and the code selects all the rows and give a count where these rows within the 6 months of the Date_Created variable.
    For e.g if Date_Created is 1/10/2018 then the six months less is 1/04/2018. so the code should all the rows which are within this time period. Like that it should do for all the rows and create new less than 6 month for each row.

  2. The second objective is it to create another column called "total" which is the sum of all the values in column "nos" which satisfies the above conditions.
    structure(list(Id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
    11L, 12L, 13L, 14L, 15L, 16L, NA, NA, NA), nos = c(10L, 2L, 3L,
    4L, 1L, 1L, 2L, 2L, 2L, 2L, 4L, 2L, 3L, 2L, 2L, 2L, NA, NA, NA
    ), department = c("A", "A", "A", "B", "B", "A", "C", "A", "B",
    "C", "B", "B", "C", "A", "A", "A", "", "", ""), location = c("delhi",
    "delhi", "london", "london", "london", "delhi", "chennai", "chennai",
    "delhi", "delhi", "delhi", "chennai", "chennai", "london", "delhi",
    "delhi", "", "", ""), grade = c(3L, 3L, 4L, 4L, 4L, 4L, 3L, 3L,
    3L, 4L, 3L, 3L, 4L, 3L, 4L, 4L, NA, NA, NA), Date_Created = c("1/8/2018",
    "1/8/2018", "1/10/2018", "1/15/2018", "1/25/2018", "2/21/2018",
    "2/26/2018", "2/27/2018", "3/19/2018", "5/14/2018", "5/15/2018",
    "5/21/2018", "5/21/2018", "5/25/2018", "6/5/2018", "6/26/2018",
    "", "", ""), X = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
    NA, NA, NA, NA, NA, NA, NA, NA)), class = "data.frame", row.names = c("1",
    "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
    "14", "15", "16", "17", "18", "19"))