R Version 2.11.1 32-bit on Windows 7
I get a data set as below:
USER_A USER_B SCORE
1 6 0.2
1 7 0.1
1 10 0.15
2 6 0.2
2 9 0.12
3 8 0.15
3 9 0.3
the USER_A is 1:3 and the USER_B is 6:10. Now I need to output the USER_A with the ranking of USER_B by their SCORE:
USER_A ranking of USER_B
1 3 1 2 #the ranking of USER_B 6,7,10(which belong to USER_A 1)
2 2 1 #the ranking of USER_B 6,9(which belong to USER_A 2)
3 1 2 #the ranking of USER_B 8,9(which belong to USER_A 3)
in fact, I just need to output the ranking:
3 1 2
2 1
1 2
it is upset because the length of each row is different! I could not store them in a matrix and then output them.
Could anyone help me solve this problem?
One way is to split the data:
The last line gives:
An alternative is to use
aggregate()as in:Which returns:
But the output is a bit different here, now we have a data frame, with the second component
SCOREbeing a list, just like thelapply()version outputted: