Move a column to first position in a data frame

前端 未结 8 1541
别那么骄傲
别那么骄傲 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-22 23:58

    If you want to move any named column to the first position, simply use:

    df[,c(which(colnames(df)=="desired_colname"),which(colnames(df)!="desired_colname"))]
    

提交回复
热议问题