paste function in r
<p>I would think this should be an extremely easy solve; but, I can't find it on here; and, the instructions that I've found elsewhere haven't worked. All I'm trying to do is use a simple paste function.</p>

<p>In my data frame, I have a date variable formatted "yymmdd":</p>

<pre><code>&gt; str(g.2015.1990$DATE)
 int [1:60464] 150410 150411 150412 150420 150421 150422 150423 150424 150425 150426 ...
</code></pre>

<p>R interprets this as an integer, but I need to format it as a date. My problem arises when I get to the decade 2000-2009. R drops the leading 0s. So, 2001-2009 are formatted "ymmdd"; October through December of 2000 are formatted "mmdd"; and, January through September of 2000 are formatted "mdd".</p>

<p>I figured I could break the vector up into four sections (I had to rbind it year-by-year to assemble it anyways) and paste either none, one, two, or three 0s in front, as appropriate, to create a consistent, 6-digit character string that I can then convert to a date.</p>

<p>I've not yet taken the time to break this variable up into the aforementioned sections, as I've not yet found a successful solution to my problem; however, here is what I've tested on the variable in its entirety:</p>

<pre><code>datex = paste("0", g.2015.1990$DATE, sep = "")
datex = paste(0, g.2015.1990$DATE, sep = "")
datex = paste("0", as.character(g.2015.1990$DATE), sep = "")
datex = paste(0, as.character(g.2015.1990$DATE), sep = "")
</code></pre>

<p>Each one returns the same error:</p>

<pre><code>Error in View : 'names' attribute [1254] must be the same length as the vector [1]
</code></pre>

<p>Please tell me what I'm doing wrong! I swear this should be such as easy fix.</p>