[R] Outputting csv file from dataframe with columns in a particular order
Ivan Calandra
ivan.calandra at uni-hamburg.de
Wed Jan 12 16:34:02 CET 2011
Hi!
Let's say your data.frame is called df and that you want column 1, then
column 4, then 3 and then 2:
df <- data.frame(ID=LETTERS[1:5], date=rnorm(5), estimate=rnorm(5),
actual=rnorm(5))
write.csv(df[c(1,4,3,2)], file="df.csv")
HTH,
Ivan
Le 1/12/2011 16:16, analyst41 at hotmail.com a écrit :
> I have a dataframe with columns "ID",'date","estimate","actual" (but
> not necessarily in that order - I do a merge somewhere and that
> somehow messes up the order of the columns).
>
> How can I output it to a csv file with the columns in the order that I
> want?
>
> 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.
>
--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de
**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php
More information about the R-help
mailing list