title: Convert date in YYYY-MM-DD format to YYYY-MM
body: <p>I would like do perform the reverse of <a href="https://stackoverflow.com/questions/33058938/r-converting-a-factor-yyyy-mm-to-a-date">R converting a factor YYYY-MM to a date</a>.</p>
  
  <p>I have a data frame (df) with dates presented as YYYY-MM-DD format (column "Date1") and would like to convert them into YYYY-MM format. The days range between 0-31 but these aren't necessary for my YYYY-MM format.</p>
  
  <p>The point is that I have another set of columns that are in YYYY-MM format (column "Date2") and want to calculate the differences between them in whole months (values x, y and z in column "Difference(months)")</p>
  
  <pre><code>Date1       Date2    Difference(months)
  2008-08-11  1995-02    x
  2010-06-18  1972-09    y
  2011-04-22  1956-11    z
  </code></pre>
  
  <p>Doing <code>df$Date1_new &lt;- as.Date(df$Date1, "%Y-%m")</code> just gives a series of "NA" values.</p>
  
  <p>Please can you give me a way that does what I am asking for or another easier method that gives the same desired result?</p>