描述
使用与’ select_dt() ‘相同的语法更改列的位置。
检查与dplyr中的“relocate”类似的功能。
df <- data.table(a = 1, b = 1, c = 1, d = "a", e = "a", f = "a")
df
df %>% relocate_dt(f) #默认how='first'
df %>% relocate_dt(a,how = "last")
df %>% relocate_dt(is.character) #默认how='first'
df %>% relocate_dt(is.numeric, how = "last")
df %>% relocate_dt("[aeiou]") #指定位置
df %>% relocate_dt(a, how = "after",where = f)
df %>% relocate_dt(f, how = "before",where = a)
df %>% relocate_dt(f, how = "before",where = c)
df %>% relocate_dt(f, how = "after",where = c)
df2 <- data.table(a = 1, b = "a", c = 1, d = "a")
df2 %>% relocate_dt(is.numeric,
how = "after",
where = is.character)
df2 %>% relocate_dt(is.numeric,
how="before",
where = is.character)