title: How can I define a function in r to flag holidays by week?
body: <p>I have a field of dates that mark the end of weeks. I am trying to create a new field using a function that flags (1 or 0) whether that week included any of 6 holidays specified using the timeDate package. I am getting the following error: "Error during wrapup: comparison (3) is possible only for atomic and list types" - how can I resolve?</p>
  
  <p>The function should take the end-of-week date (x) in the format yyyy-mm-dd (e.g., 2017-01-01) and the year of that date (y) in the format yyyy (e.g., 2017).</p>
  
  <pre><code>library(lubridate)
  library(timeDate)
  
  Date = as.Date(c("2017-01-01", "2017-01-08", "2017-01-15", "2017-01-22", "2017-06-04", "2017-07-09", "2017-07-16"))
  Year = year(Date)
  Holiday.During.Week = as.Date(c("2017-01-01", NA, NA, NA, "2017-05-29", "2017-07-04", NA))
  Desired.Output = c(1,0,0,0,1,1,0)
  data &lt;- data.frame(Date, Year, Holiday.During.Week, Desired.Output)
  data
  
  holiday.function = function(x, y) {
    return(
      as.numeric(
        (USNewYearsDay(y) &lt; x &amp; USNewYearsDay(y) &gt; (x - 7)) +
        (USMemorialDay(y) &lt; x &amp; USMemorialDay(y) &gt; (x - 7)) +
        (USIndependenceDay(y) &lt; x &amp; USIndependenceDay(y) &gt; (x - 7)) +
        (USLaborDay(y) &lt; x &amp; USLaborDay(y) &gt; (x - 7)) +
        (USThanksgivingDay(y) &lt; x &amp; USThanksgivingDay(y) &gt; (x - 7)) +
        (USChristmasDay(y) &lt; x &amp; USChristmasDay(y) &gt; (x - 7))
      )
    )
  }
  data$Holiday.Flag = holiday.function(data$Date, data$Year)
  </code></pre>
  
  <p>Edit: thanks to Ian Campbell for working on this without provided data. I've updated the code to include a sample data frame and libraries</p>