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

前端 未结 17 1616
耶瑟儿~
耶瑟儿~ 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:17

    You can do it like below -

    df <- data.frame(a=1:4, b=5:8, c=9:12)
    df['d'] <- seq(10,13)
    df <- df[,c('a','b','d','c')]
    

提交回复
热议问题