[R] inserting columns in the middle of a dataframe

Timothy Bates timothy.c.bates at gmail.com
Thu Sep 14 00:04:42 CEST 2006


> Is there a built-in and simple way to insert new columns in a dataframe?

You do this by collecting the columns in the new order you desire, and
making a new frame.

oldframe           <- data.frame(matrix(0:14,ncol=3))
newcol              <- data.frame(20:24)
names(newcol) <- "newcol"
newframe         <- data.frame(c(oldframe[1],newcol, oldframe[2:3]))



More information about the R-help mailing list