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

后端 未结 6 1186
旧时难觅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:49

    The package dplyr and the function dplyr::relocate, a new verb introduced in dplyr 1.0.0, does exactly what you are looking for.

    library(dplyr)

    data %>% relocate(v17, v18, .before = v13)

    data %>% relocate(v6, v16, .after = last_col())

    data %>% relocate(age, .after = gender)

提交回复
热议问题