title: Convert multiple character columns to as.Date and time in R
body: <p>We have an arbitrary dataset, called df:</p>
  <pre><code>enter &lt;- c(&quot;2017-01-01&quot;, &quot;2018-02-02&quot;, &quot;2018-03-03&quot;) 
  guest &lt;- c(&quot;Foxtrot&quot;,&quot;Uniform&quot;,&quot;Charlie&quot;,&quot;Kilo&quot;)
  disposal &lt;- c(&quot;2017-01-05&quot;, &quot;2018-02-05&quot;, &quot;2018-03-09&quot;) 
  rating &lt;- c(&quot;60&quot;,&quot;50&quot;,&quot;50&quot;)
  date &lt;- c(&quot;2017-04-10&quot;, &quot;2018-04-15&quot;, &quot;2018-04-20&quot;)
  clock &lt;- c(&quot;16:02:00&quot;, &quot;17:02:00&quot;, &quot;18:02:00&quot;)
  rolex &lt;- c(&quot;20:10:00&quot;, &quot;20:49:00&quot;, &quot;17:44:00&quot;) 
  df &lt;- data.frame(enter,guest,disposal,rating,date,clock,rolex, stringsAsFactors = F)
  </code></pre>
  <p>What I try to accomplish is to change the columns <em>enter</em>, <em>disposal</em>, and <em>date</em> from character to date, using <em>dplyr</em> package.
  So, I came up with the following, simply by chaining it together:</p>
  <pre><code>library(dplyr)
  library(chron)
  df2 &lt;- df %&gt;% mutate(enter = as.Date(enter, format = &quot;%Y-%m-%d&quot;)) 
  %&gt;% mutate(disposal = as.Date(disposal, format = &quot;%Y-%m-%d&quot;)) 
  %&gt;% mutate(date = as.Date(date, format = &quot;%Y-%m-%d&quot;))
  </code></pre>
  <p>What I am after is this: which <strong>mutate</strong> function is needed from dplyr to get rid of the multiple chaining, i.e. when we have lots of columns with arbitrary namings that imply dates? I want to specify the columns by name, and then apply the as.Date function to change them from character to date.</p>
  <p>Some solutions to different operations that are not applicable to this case:</p>
  <p>1: <a href="https://stackoverflow.com/questions/33408636/convert-column-in-data-frame-to-date">convert column in data.frame to date</a></p>
  <p>2: <a href="https://stackoverflow.com/questions/43264068/convert-multiple-columns-to-dates-with-lubridate-and-dplyr">convert multiple columns to dates with lubridate and dplyr</a></p>
  <p>3: <a href="https://stackoverflow.com/questions/48501059/change-multiple-character-columns-to-date">change multiple character columns to date</a></p>
  <p>For example, I've tried, but with no luck:</p>
  <pre><code>df2 &lt;- df %&gt;% mutate_at(data = df, each_of(c(enter, disposal, date)) = as.Date(format = &quot;%Y-%m-%d&quot;))
  </code></pre>
  <p>as given here: <a href="https://stackoverflow.com/questions/27668266/dplyr-change-many-data-types">dplyr change many data types</a></p>
  <h2>As a bonus</h2>
  <p>Notice the <em>clock</em> and <em>rolex</em> columns. Using the chron package simply converts them to the right format, i.e. time instead of character</p>
  <pre><code>df2 &lt;- df %&gt;% mutate(clock = chron(times = clock)) %&gt;% mutate(rolex = chron(times = rolex))
  </code></pre>
  <p>As suggested here:
  <a href="https://stackoverflow.com/questions/12034424/convert-character-to-time-in-r">convert character to time in r</a></p>
  <p>Now, is the same solution available without all the chaining, especially when we have an arbitrary amount of columns with different namings etc.?</p>