Move a column to first position in a data frame

前端 未结 8 1540
别那么骄傲
别那么骄傲 2020-12-22 23:30

I would like to have the last column of the data frame moved to the start (as first column). How can I do it in R?

My data.frame has about a thousand columns to chan

8条回答
  •  醉话见心
    2020-12-23 00:05

    Move any column from any position for the first position in your data

    n <- which(colnames(df)=="column_need_move")
    column_need_move <- df$column_need_to_move
    df <- cbind(column_need_move, df[,-n])
    

提交回复
热议问题