[R] Outputting csv file from dataframe with columns in a particular order

Peter Ehlers ehlers at ucalgary.ca
Wed Jan 12 16:34:11 CET 2011


On 2011-01-12 07:16, analyst41 at hotmail.com wrote:
> 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?

Let's say that your data.frame is DF.
mynames <- c("ID", "date", "estimate", "actual")
write.csv(DF[, mynames], ....)

Peter Ehlers



More information about the R-help mailing list