title: How to avoid date formatted values getting converted to numeric when assigned to a matrix or data frame?
body: <p>I have run into an issue I do not understand, and I have not been able to find an answer to this issue on this website (I keep running into answers about how to convert dates to numeric or vice versa, but that is exactly what I do not want to know).</p>
  
  <p>The issue is that R converts values that are formatted as a date (for instance "20-09-1992") to numeric values when you assign them to a matrix or data frame.
  For example, we have "20-09-1992" with a date format, we have checked this using <code>class()</code>. </p>
  
  <pre><code>as.Date("20-09-1992", format = "%d-%m-%Y")
  class(as.Date("20-09-1992", format = "%d-%m-%Y"))
  </code></pre>
  
  <p>We now assign this value to a matrix, imaginatively called Matrix:</p>
  
  <pre><code>Matrix &lt;- matrix(NA,1,1)
  Matrix[1,1] &lt;- as.Date("20-09-1992", format = "%d-%m-%Y")
  Matrix[1,1]
  class(Matrix[1,1])
  </code></pre>
  
  <p>Suddenly the previously date formatted "20-09-1992" has become a numeric with the value 8298. I don't want a numeric with the value 8298, I want a date that looks like "20-09-1992" in date format.</p>
  
  <p>So I was wondering whether this is simply how R works, and we are not allowed to assign dates to matrices and data frames (somehow I have managed to have dates in other matrices/data frames, but it beats me why those other times were different)? Is there a special method to assigning dates to data frames and matrices that I have missed and have failed to deduce from previous (somehow successful) attempts at assigning dates to data frames/matrices?</p>