title: Min and max for each row with dataframe in R
body: <p>I need to calculate the processing time for several people who have taken an online test. So for each person there are numerous timestamps (one timestamp per task). The duration of the processing is calculated from the time difference between the smallest and the largest date value. The following example works (student_1), but it only works if no value is missing (student_2 and student_3). Are there any ideas?</p>
  <pre><code>library(anytime)
  
  number &lt;- c(1, 2, 3)
  uniquename &lt;- c(&quot;student_1&quot;, &quot;student_2&quot;,  &quot;student_3&quot;)
  timestamp_1 &lt;- c(anytime(&quot;2020-02-25T12:42:56.476Z&quot;),NA,anytime(&quot;2020-02-25T10:05:22.388Z&quot;))
  timestamp_2 &lt;- c(anytime(&quot;2020-02-25T12:51:22.388Z&quot;),anytime(&quot;2020-02-25T12:51:22.388Z&quot;),NA)
  timestamp_3 &lt;- c(anytime(&quot;2020-02-25T13:00:45.042Z&quot;),anytime(&quot;2020-02-25T13:00:45.042Z&quot;),NA)
  timestamp_4 &lt;- c(anytime(&quot;2020-02-25T13:31:48.073Z&quot;),anytime(&quot;2020-02-25T13:31:48.073Z&quot;),NA)
  timestamp_5 &lt;- c(anytime(&quot;2020-02-25T14:22:57.103Z&quot;),anytime(&quot;2020-02-25T15:00:00Z&quot;),anytime(&quot;2020-02-25T14:05:00Z&quot;))
  
  df3 &lt;- data.frame(number,
                    uniquename,
                    timestamp_1,
                    timestamp_2,
                    timestamp_3,
                    timestamp_4,
                    timestamp_5)
  
  df3$date_min &lt;- apply(df3[3:7], 1, FUN=min)
  df3$date_max &lt;- apply(df3[3:7], 1, FUN=max)
  
  df3$date_min &lt;- anytime(df3$date_min)
  df3$date_max &lt;- anytime(df3$date_max)
  
  df3$diff &lt;- difftime(df3$date_min, df3$date_max, units = &quot;mins&quot;)
  df3$diff &lt;- round(df3$diff,0)
  df3$diff &lt;- as.numeric(df3$diff)*(-1)
  
  View(df3)
  </code></pre>