Add (insert) a column between two columns in a data.frame

前端 未结 17 1617
耶瑟儿~
耶瑟儿~ 2020-11-28 02:41

I have a data frame that has columns a, b, and c. I\'d like to add a new column d between b and c.

I know I could just add d at the end by using cbind but h

17条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 03:14

    Add in your new column:

    df$d <- list/data
    

    Then you can reorder them.

    df <- df[, c("a", "b", "d", "c")]
    

提交回复
热议问题