Hi,

i am merging two data frames of different time periods, so that the result
contains data from both for the same time period.
however, I want the result to output columns in a certain order.
the common column between the two data frames is date.

for example:

df1 columns:
mod1 mod2 mod3 mod4 date  #(there are actually 691 mod columns)

df2 columns:
obs wy date

after merge, i want the order of the columns to be all mod data columns
from df1, followed by the obs and wy columns from df2, followed by the date
column.

i almost get want i want with (at least it doesn't put the common column
date as the first column as merge does by default):

new = merge(df1, df2, by=c("date"))[, union(names(df1), names(df2))]

however, that of course gives me all of df1 followed by all of df2, which
doesn't put obs immediately after the mod columns:

what i get:
mod1 mod2 mod3 mod4 date obs wy

what i want:
mod1 mod2 mod3 mod4 obs wy date

any suggestions on how to output the columns in the order i want, without
having to rearrange the order after the fact?

thank you for any help!
Janet

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to