r - Wrong order result inside data.table function -


I've found that inside the data (), the order function calculates rows by groups, while viewing the basic idea rank For each observation within specified groups

Here is a presentable example:

  is required (data is qualified) N & lt; - 10 sets .seed (1) test & lt; - Data is eligible (A = round (rhinum (n, mid = 0, sd = 30), 0), b = c (rip ('group_1', n / 2), representative ('group_2', n / 2)) Examination (test, b, item_position) see test (test)  

Result (test, b, item_position) test [, item_point: command = (a, decreasing = t), = list (b)] (As I get it):

  test ab item_position 1: 48 group_1 1 2: -25 group_1 2 3: 10 group_1 3 4: -19 group_1 4 5: 6 group_1 5 6 : -9 Group_2 1 7: 22 Group_2 2 8: -25 Group_2 3 9: 15 group_2 4 10: 17 group_2 5  

Which is clear What's wrong with what I am doing wrong, and how can I use the command inside data.table?

Thank you!

I think you have a misunderstanding that order does everything you describe, you actually rank :

  test [, bsc: = rank (-a, relations. "First") are in search of, by = b] [] ## Big to Small # AB BIT # 1: -19 Group_1 4 # 2: 6 Group_1 3 #. SNIP .. # 9: 17 Group_2 2 # 10: -9 Group_2 4 Test [, SBB : = Rank (A, relations. Method = "first"), by = b] [] ## small to large # AB BSTS SB # 1: -19 Group_1 4 2 # 2: 6 Group_1 3 3 # .. SNIP # 9: 17 Group_2 2 4 # 10: -9 Group_2 4 Set 2 (Test, B, S_B) Exam # AB BSD S_BS # 1: -25 Group_1 5 1 # 2: -19 Group_1 4 2 # 3: 6 Group_1 3 3 # 4: 10 Group_1 2 4 # 5: 48 Group_1 1 5 # 6: -25 Group_2 5 1 # 7: -9 Group_2 4 2 # 8: 15 Group_2 3 3 # 9: 17 Group_2 2 4 # 10: 22 There was nothing  wrong  with group output (except that it was not your hope). Consider the following:  
  x  

This is what is You were receiving your data.table in the north. To see more about the Orders function, see this Q & A set:


Comments