[R] Inverting data frame...row wise

David Scott d.scott at auckland.ac.nz
Fri Sep 26 02:25:40 CEST 2008


On Thu, 25 Sep 2008, Julian Burgos wrote:

> How about something like
>
> my.data=my.data[,4:1]
>
> Julian
>

This can be tackled in a similar way to the question by Mark Na which I 
just answered. Using the same data frame construction we have

> df <- data.frame(k1=1:2,k2=3:4,z=5:6,a=7:8,y=9:10)
> df
   k1 k2 z a  y
1  1  3 5 7  9
2  2  4 6 8 10
> revdf <- df[,rev(names(df))]
> revdf
    y a z k2 k1
1  9 7 5  3  1
2 10 8 6  4  2



David Scott


> milicic.marko wrote:
>> Hi,
>> 
>> I have the data.frame with 4 columns. I simply want to invert dataset
>> so that last row becomes first...
>> 
>> I tried with rev(my_data-frame) but I got my columns inverted... not
>> my rows
>> 
>> 
>> Thanks
>> 
>> ______________________________________________
>> R-help at r-project.org 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 at r-project.org 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 Scott	Department of Statistics, Tamaki Campus
 		The University of Auckland, PB 92019
 		Auckland 1142,    NEW ZEALAND
Phone: +64 9 373 7599 ext 86830		Fax: +64 9 373 7000
Email:	d.scott at auckland.ac.nz

Graduate Officer, Department of Statistics
Director of Consulting, Department of Statistics



More information about the R-help mailing list