I have a data set as given in example data set employee:
s.no e.name s.date e.date s.time e.time total.hrs
1 George 1-Jan-19 10-Jan-19 10:45 11:45 1
2 George 10-Jan-19 15-Jan-19 06:00 09:00 3
3 George 15-Jan-19 15-Jan-19 12:00 03:00 3
4 George 5-Feb-19 18-Feb-19 12:50 14:50 2
5 Jacob 2-Feb-19 20-Feb-19 15:50 16:50 1
6 Jacob 20-Feb-19 24-Feb-19 14:30 18:30 4
7 Jacob 3-Dec-19 25-Dec-19 06:40 11:40 5
8 Jacob 25-Dec-19 30-Dec-19 09:40 12:40 3
9 Mike 02-Jun-19 02-Jun-19 6:40 07:40 1
10 Mike 02-Jun-19 02-Jun-19 2:45 3:45 1
11 Mike 02-Jun-19 20-Jun-19 10:00 12:00 2
12 Mike 23-Jun-19 25-Jun-19 4:00 5:00 1
My desired output is:
s.no e.name s.date e.date s.time e.time total.hrs
1 George 1-Jan-19 15-Jan-19 10:45 03:00 7
2 George 5-Feb-19 18-Feb-19 12:50 14:50 2
3 Jacob 2-Feb-19 24-Feb-19 15:50 18:30 5
4 Jacob 3-Dec-19 30-Dec-19 06:40 12:40 8
5 Mike 2-Jun-19 20-Jun-19 6:40 12:00 4
6 Mike 23-Jun-19 25-Jun-19 4:00 5:00 1
I was using dplyr library to summarize this but i was having some problem with that i was using this code but i'm not getting my desired output
employee <- employee %>% group_by(e.name) %>% summarise(
s.date=first(s.date),
e.date=last(e.date),
s.time=first(s.time),
e.time=last(e.time),
total.hrs=sum(total.hrs))
From my code i'm getting result as follows
s.no e.name s.date e.date s.time e.time total.hrs
1 George 1-Jan-19 18-Jan-19 10:45 14:50 6
2 Jacob 2-Feb-19 30-Dec-19 15:50 12:40 12
but i want my result like this
s.no e.name s.date e.date s.time e.time total.hrs
1 George 1-Jan-19 15-Jan-19 10:45 03:00 7
2 George 5-Feb-19 18-Feb-19 12:50 14:50 2
3 Jacob 2-Feb-19 24-Feb-19 15:50 18:30 5
4 Jacob 3-Dec-19 30-Dec-19 06:40 12:40 8
5 Mike 2-Jun-19 20-Jun-19 6:40 12:00 4
6 Mike 23-Jun-19 25-Jun-19 4:00 5:00 1