title: is there a way to handle a messy variable in R?
body: <p>I have the following dataset. I am trying to pivot_wider that each tmc_code be a column and the values are from speed. and then lag and lead some values. However, if you look at tmc_code, the values are weird and I cannot change them. I want to give them names that I can deal with. for example, the value &quot;119+04117&quot; better be &quot;tmc119_04117&quot;. I guess R does not like the &quot;+&quot; in a value or a variable. Please let me know if I need to restate the question. I know it is a messy question but my dataset is really confusing. Here is a sample of my dataset.</p>
  <pre><code>data&lt;- structure(list(tmc_code = c(&quot;119P04108&quot;, &quot;119P04109&quot;, &quot;119+04117&quot;,
                                     &quot;119+04106&quot;, &quot;119+04110&quot;, &quot;119+04113&quot;, 
                                    &quot;119+04111&quot;, &quot;119P04107&quot;, &quot;119+04110&quot;, 
                                    &quot;119P04117&quot;, &quot;119+04114&quot;, &quot;119+04107&quot;,
                                     &quot;119+04112&quot; ), 
               measurement_tstamp = c(&quot;2020-06-05 20:10:00&quot;, &quot;2020-08-26 10:30:00&quot;, 
                                      &quot;2020-11-15 18:20:00&quot;, &quot;2020-10-16 13:20:00&quot;,  
                                      &quot;2020-09-17 00:20:00&quot;, &quot;2020-02-09 15:10:00&quot;,  
                                      &quot;2020-03-19 09:15:00&quot;, &quot;2020-11-05 03:25:00&quot;, 
                                      &quot;2020-07-23 22:35:00&quot;, &quot;2020-11-25 22:05:00&quot;, 
                                      &quot;2020-03-28 07:40:00&quot;, &quot;2020-02-14 22:20:00&quot;, 
                                      &quot;2020-05-01 16:25:00&quot;), 
  speed = c(69, 64, 74.39, 63.37, 61.8, 71.39, 61, 68.4, 74.18, 62.8, 64, 70.98, 
            66.53)), row.names = c(NA, -13L), class = &quot;data.frame&quot;)
  </code></pre>
  <p>my code for pivot_wider is</p>
  <pre><code>data&lt;- data%&gt;%
    pivot_wider(names_from = tmc_code, values_from = speed)
  </code></pre>