title: Matrix having month(integer) and year(integer), I want it to be extracted in Date or POSIX format using R
body: <p>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.</p>
  
  <pre><code># If the date is before 15th of a month, will consider previous month. Else current month
  myDateFun &lt;- function(x){
        x &lt;- as.Date(x, format='%d-%m-%Y')
        if (day(x) &lt; 15){
          dd &lt;- x-14 
        }
        else {dd &lt;- 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
  </code></pre>