Is there an equivalent R function to Stata 'order' command?

后端 未结 6 1184
旧时难觅i
旧时难觅i 2021-01-13 11:09

\'order\' in R seems like \'sort\' in Stata. Here\'s a dataset for example (only variable names listed):

v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v

6条回答
  •  孤街浪徒
    2021-01-13 11:53

    It is very unclear what you would like to do, but your first sentence makes me assume you would like to sort dataset.

    Actually, there is a built-in order function, which returns the indices of the ordered sequence. Are you searching this?

    > x <- c(3,2,1)
    
    > order(x)
    [1] 3 2 1
    
    > x[order(x)]
    [1] 1 2 3
    

提交回复
热议问题