title: `by()` changed POSIXct to numeric value in R
body: <p>In R, how to prevent the <code>by()</code> function from changing POSIXct to numeric values automatically?</p>
  <hr />
  <p>In the following example, the <code>time</code> object is class  <code>&quot;POSIXct&quot; &quot;POSIXt&quot;</code>. When using <code>by()</code> function, the output is <code>numeric</code>. But when doing what <code>by()</code> does manually, e.g. <code>min(time[index=='a'])</code>, the output is still <code>&quot;POSIXct&quot; &quot;POSIXt&quot;</code>, which is desired. Is there a way to prevent the <code>by()</code> function from changing POSIXct to numeric values automatically?</p>
  <pre><code>time = c(&quot;0001-03-04 05:36:00 UTC&quot;, &quot;0001-03-04 05:50:00 UTC&quot;, &quot;0001-03-04 06:05:00 UTC&quot;)
  time = as.POSIXct(time, tz = &quot;UTC&quot;)
  index = c(&quot;a&quot;, &quot;a&quot;, &quot;b&quot;)
  
  by(time, index, min) # results are numeric values.
  min(time[index=='a']) # &quot;0001-03-04 05:36:00 UTC&quot;
  </code></pre>