rearrange data according to pattern

This question already has an answer here:

  • How to sort a dataframe by multiple column(s)? 16 answers

  • If there is only one male and female per household, then you can just do:

    dta <- dta[order(dta$householdid.x, dta$isex), ]
    

    Which gives the desired output:

      householdid.x    idno   isex iage
    1        101366 1013661 FEMALE   29
    2        101366 1013662   MALE   36
    4        102481 1024811 FEMALE   29
    3        102481 1024812   MALE   39
    6        103755 1037551 FEMALE   31
    5        103755 1037552   MALE   36
    

    And if I'm not mistaken, this was the 100,000th question with the r tag!

    链接地址: http://www.djcxy.com/p/70862.html

    上一篇: Google将方向API重定向到map.google.com

    下一篇: 根据模式重新排列数据