title: Why are my functions on lubridate dates so slow?
body: <p>I wrote this function which I use all the time:</p>
  
  <pre><code># Give the previous day, or Friday if the previous day is Saturday or Sunday.
  previous_business_date_if_weekend = function(my_date) {
      if (length(my_date) == 1) {
          if (weekdays(my_date) == "Sunday") { my_date = lubridate::as_date(my_date) - 2 }
          if (weekdays(my_date) == "Saturday") { my_date = lubridate::as_date(my_date) - 1 }
          return(lubridate::as_date(my_date))
      } else if (length(my_date) &gt; 1) {
          my_date = lubridate::as_date(sapply(my_date, previous_business_date_if_weekend))
          return(my_date)
      }
  }
  </code></pre>
  
  <p>Problems arise when I apply it to a date column of a dataframe with thousands of rows.  It's ridiculously slow.  <strong>Any thoughts as to why?</strong></p>