Sort columns of a dataframe by column name

后端 未结 9 603
自闭症患者
自闭症患者 2020-11-27 10:48

This is possibly a simple question, but I do not know how to order columns alphabetically.

test = data.frame(C = c(0, 2, 4, 7, 8), A = c(4, 2, 4, 7, 8), B =          


        
9条回答
  •  余生分开走
    2020-11-27 11:47

    Here's the obligatory dplyr answer in case somebody wants to do this with the pipe.

    test %>% 
        select(sort(names(.)))
    

提交回复
热议问题