I just started learning R programming and have few doubts about working on repeated values specifically in a single column of a data frame. For example consider a ‘Sample’ dataframe `
> Sample
id time1 time2 user group
21 21 21.7 16.1 A 1
22 22 22.6 17.0 A 2
23 23 20.9 16.2 A 3
24 24 21.6 16.2 B 1
25 25 22.2 16.9 B 1
26 26 22.5 16.9 B 1
27 27 22.2 17.3 B 2
28 28 24.3 16.8 D 2
29 29 22.3 16.8 D 2
30 30 22.6 17.0 E 3
31 31 20.1 16.5 E 3
32 32 22.0 16.9 E 3
33 33 22.8 16.5 E 4
34 34 22.0 17.0 E 4
35 35 22.4 17.0 F 1
36 36 22.3 16.3 F 1
37 37 20.6 16.2 F 2
Now I need to find
1) the user with highest average ‘time1’
2) the user belonging to ‘group’ 3 and having biggest ‘time2’
As of now my understanding is that I should use combination of repeated(), unique(), max() and mean() and NROW() functions. But I am having trouble trying to figure that out. Any pointers on how to approach?
You can use
which.maxandtapply:1)
2)
Be careful of ties though.