title: Dataframe to tidy format in R
body: <p>I've this dataframe</p>
  <pre><code>x &lt;- data.frame(&quot;date&quot; = c(&quot;03-01-2005&quot;,&quot;04-01-2005&quot;,&quot;05-01-2005&quot;,&quot;06-01-2005&quot;), 
                  &quot;pricemax.0&quot; = c(50,20,25,56), 
                  &quot;pricemax.200&quot; = c(25,67,89,30),
                  &quot;pricemax.1000&quot; = c(45,60,40,30),
                  &quot;pricemax.1400&quot; = c(60,57,32,44),
                  &quot;pricemin.0&quot; = c(22,15,23,43),
                  &quot;pricemin.200&quot; = c(21,40,59,21),
                  &quot;pricemin.1000&quot; = c(32,12,20,24),
                  &quot;pricemin.1400&quot; = c(30,20,14,20))
  </code></pre>
  <p>The numbers after the dot represents hours, e.g <code>pricemax.200</code> would be 02:00. I need to gather the date and time information in one column of class <code>POSIXct</code> with the other two columns being <code>pricemax</code> and <code>pricemin</code>.</p>
  <p>So, what I want is something like this:</p>
  <p><a href="https://i.stack.imgur.com/k1D77.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k1D77.png" alt="Tidy dataframe" /></a></p>
  <p>And what I've done so far:</p>
  <pre><code>tidy_x &lt;- x %&gt;% 
        pivot_longer(
          cols = contains(&quot;pricemax&quot;),
          names_to = c(NA,&quot;hour&quot;),
          names_sep = &quot;\\.&quot;,
          values_to = &quot;pricemax&quot;
        ) %&gt;% 
        pivot_longer(
          cols = contains(&quot;pricemin&quot;),
          names_to = c(NA,&quot;hour_2&quot;),
          names_sep = &quot;\\.&quot;,
          values_to = &quot;pricemin&quot;
        )
  </code></pre>
  <p>I'm not sure how I can combine the date and time columns and keep the variables <code>pricemin</code> and <code>pricemax</code> organized.</p>