I can not figure this out. I have a data frame
id=c(1,2,3,4,2,6,1,1,6,5,4,2)
per=c(0.1,0.9,0.6,0.5,0.8,0.9,0.2,0.3,0.7,0.5,0.4,0.3)
df=data.frame(id=id,per=per)
I want to divide the "per" column in three conditions, lets say, between 0 and 0.3 (we assign a 3), 0.3 and 0.7 (we assign a 2), and 0.7 and 1 (we assign a 1).
My idea is to assign each unique id to the largest count of this division, i.e., if for id=1 there are more "per" in the 0.7-1 range, then that id corresponds to that division, i.e., id = 1 corresponds to "1". So the example would look like:
id class
1 3
2 1
3 2
4 2
5 2
6 1
I found this
R- selecting a row based on characteristics of another column in that row
but I need the previous step, i.e., the classification, to reach that point.
Thank you!