Another way is to use attach(dataframe)

x1 <- rep(1,10)
x2 <- rep(2,10)
x3 <- rep(3,10)
x4 <- rep(4,10)
x5 <- rep(5,10)

dat <- data.frame(x1,x2,x3,x4)
rm(x1,x2,x3,x4)
attach(dat)
dat2 <- data.frame(x1,x5,x2,x3,x4)
detach(dat)



On 13/09/06, Timothy Bates <timothy.c.bates@gmail.com > wrote:
>
>
> > 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]))
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
=================================
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP


-- 
=================================
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

	[[alternative HTML version deleted]]

