title: Convert Time to Fraction and Average in R
body: <p>I need to get the mean of times in column "ci" [c]lock-[i]n. The data is in character format, e.g. "8:05 AM". I can use the below code to reformat and get the data to a point wherein I can compute a mean:</p>
  
  <pre><code>hrs$ci &lt;- strptime(hrs$ci, format = "%I:%M %p")
  mean(hrs$ci)
  </code></pre>
  
  <p>But for some reason when I try to use dcast to create a table...</p>
  
  <pre><code>hrs &lt;- dcast(hrs, Office ~ Week, value.var = "ci", fun.aggregate = mean)
  </code></pre>
  
  <p>...it doesn't work and I get this error:</p>
  
  <pre><code>Error in dim(ordered) &lt;- ns : dims [product 900] do not match the length of object [9900]
  </code></pre>
  
  <p>Any ideas on what I am doing wrong? Or have a suggestion for a better way? In the end I am trying to get the table that the dcast would provide with average clock-in times by week for each office.</p>
  
  <p>Ideally at the end I would have the fraction of a day (i.e. 0.50 = noon) for the time, but I could probably work with alternative formats.</p>