描述

    使用与’ select_dt() ‘相同的语法更改列的位置。

    检查与dplyr中的“relocate”类似的功能。

    改变列在数据框的位置顺序 - 图1

    1. df <- data.table(a = 1, b = 1, c = 1, d = "a", e = "a", f = "a")
    2. df
    3. df %>% relocate_dt(f) #默认how='first'
    4. df %>% relocate_dt(a,how = "last")
    5. df %>% relocate_dt(is.character) #默认how='first'
    6. df %>% relocate_dt(is.numeric, how = "last")
    7. df %>% relocate_dt("[aeiou]") #指定位置
    8. df %>% relocate_dt(a, how = "after",where = f)
    9. df %>% relocate_dt(f, how = "before",where = a)
    10. df %>% relocate_dt(f, how = "before",where = c)
    11. df %>% relocate_dt(f, how = "after",where = c)
    12. df2 <- data.table(a = 1, b = "a", c = 1, d = "a")
    13. df2 %>% relocate_dt(is.numeric,
    14. how = "after",
    15. where = is.character)
    16. df2 %>% relocate_dt(is.numeric,
    17. how="before",
    18. where = is.character)