0

I have my table(input)

  user_id   timestamp  session
1 Helen     12         25
2 Helen     10         24
3 Helen     8          20
4 Rob       30         31
5 Rob       20         40

I want to leave in table rows for every user_id where timestamp value is minimum (output)

 user_id   timestamp  session
    1 Helen     8          20
    2 Rob       20         40

THX for your help!!!

Smasell
  • 1,206
  • 2
  • 13
  • 21
  • See also [this](http://stackoverflow.com/questions/4189807/only-keep-min-value-for-each-factor-level) and [this](http://stackoverflow.com/questions/21046425/how-to-select-rows-by-group-with-the-minimum-value-and-containing-nas-in-r) and here is some info regarding that thing some call ["Google"](https://en.wikipedia.org/wiki/Google_Search) – David Arenburg May 04 '16 at 14:35

1 Answers1

0

With library dplyr, you can do something like this:

library(dplyr)
df %>% group_by(user_id) %>% filter(timestamp == min(timestamp))

Source: local data frame [2 x 3]
Groups: user_id [2]

  user_id timestamp session
   <fctr>     <int>   <int>
1   Helen         8      20
2     Rob        20      40
Gopala
  • 10,363
  • 7
  • 45
  • 77