Re: [R] inserting columns in the middle of a dataframe

From: Jon Minton <jm540_at_york.ac.uk>
Date: Wed 13 Sep 2006 - 22:42:43 GMT

Thanks, but isn't that only for elements in vectors?

I think I've found the following method to work:

e.g. for
df <- data.frame(v1,v2,v3,v4)

use:

df <- data.frame(df[1:2],v5,df[-c(1:2)])

I *believe* this is the one-line solution I was looking for. Can anyone see why this wouldn't work?

Jon

-----Original Message-----
From: Christos Hatzis [mailto:christos@nuverabio.com] Sent: 13 September 2006 23:22
To: 'Jon Minton'; r-help@stat.math.ethz.ch Subject: RE: [R] inserting columns in the middle of a dataframe

See ?append

-Christos

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Jon Minton
Sent: Wednesday, September 13, 2006 5:14 PM To: r-help@stat.math.ethz.ch
Cc: 'Jon Minton'
Subject: Re: [R] inserting columns in the middle of a dataframe

Dear R users:  

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

I.e. currently I have:  

V1 V2 V3 V4

[1,]

[2,]

Etc.  

But I want

                V1 V5 V2 V3 V4

[1,]

[2,]

Etc.  

Can this be done in one line?  

Jon Minton    

        [[alternative HTML version deleted]]



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.

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. Received on Thu Sep 14 08:45:39 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 13 Sep 2006 - 23:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.