title: Split characters of a column in a dataframe to insert an underscore between values in R
body: <p>I have a dataframe with a column of dates in YYYYMMDD format. I would like to convert this column of values to YYYY_MM_DD to match the format in another database.</p>
  <p>Solutions I have found primarily focus on splitting a strings such as comma-delimited.</p>
  <p>I essentially want a solution that indexes YYYYMMDD and inserts an '_' after the 4th character and the 6th character.</p>
  <p>Thanks</p>
  <p><strong>UPDATE:</strong></p>
  <p>After posting I almost immediately found a solution that worked for me:</p>
  <pre><code>library(tidyr)
  
  # create names for new columns
  newCol &lt;- c(&quot;YEAR&quot;, &quot;MONTH&quot;, &quot;DAY&quot;)
  
  # separate existing column at 4 and 6 character
  newData &lt;- separate(table, old_column, newCol, sep = c(4,6))
  
  # combining the three columns to one delimited by '_'
  table$newColumn &lt;- paste(table$YEAR, table$MONTH, table$DAY, sep = &quot;_&quot;)
  </code></pre>