I have a function created to arrive month, so that if a invoice is created before 15th of a month, will consider previous month. Else it will consider current month. The output gets stored in a matrix (2 columns and 4500 rows). One column is for months in integer and other for year in integer. Program and output below. I want the month and year to be in Date format instead of integer, so that I can slide and dice the data in visualization. Your help is appreciated.

```
# If the date is before 15th of a month, will consider previous month. Else current month
myDateFun <- function(x){
      x <- as.Date(x, format='%d-%m-%Y')
      if (day(x) < 15){
        dd <- x-14 
      }
      else {dd <- x}
      return(c(month(dd), year(dd)))
    }

    # sapply method used to absorb the function and create matrix of month and year
mat = t(sapply(CI3$invoice_date, FUN=myDateFun, simplify='matrix'))

# Output [,1] is month. [,2] is year   
mat
            [,1] [,2]
       [1,]    3 2016
       [2,]    4 2016
       [3,]    5 2016
       [4,]    6 2016

```