[R] combining dataframes into single df with all columns

2013-02-07 Thread Anika Masters
#I have 2 dataframes df1 df2. Each has a subset of all possible column names. #How do I combine the 2 tables so that they contain all column names? data1 - c('2','3', '6', '8' , '9') data2 - c('1', '2', '3', '6') df1 - data.frame(matrix(data=NA, nrow=1, ncol=length(data1),

[R] combining dataframes into single df with all columns

2013-02-07 Thread Anika Masters
#I have 2 dataframes df1 df2. Each has a subset of all possible column names. #How do I combine the 2 tables so that they contain all column names? data1 - c('2','3', '6', '8' , '9') data2 - c('1', '2', '3', '6') df1 - data.frame(matrix(data=NA, nrow=1, ncol=length(data1), dimnames=list(NULL,

Re: [R] combining dataframes into single df with all columns

2013-02-07 Thread arun
: Thursday, February 7, 2013 12:36 PM Subject: [R] combining dataframes into single df with all columns #I have 2 dataframes df1 df2.  Each has a subset of all possible column names. #How do I combine the 2 tables so that they contain all column names? data1 - c('2','3', '6', '8' , '9') data2 - c

Re: [R] combining dataframes into single df with all columns

2013-02-07 Thread Rui Barradas
Hello, The following function will give what you seem to want. fun - function(x, y){ df3 - x df3 - cbind(df3, df2[setdiff(names(y), names(x))]) df3[order(names(df3))] } fun(df1, df3) Hope this helps, Rui Barradas Em 07-02-2013 18:36, Anika Masters escreveu: #I

Re: [R] combining dataframes into single df with all columns

2013-02-07 Thread Rui Barradas
Hello, Sorry, there's a bug in my first reply. Corrected: fun - function(x, y){ df3 - cbind(x, y[setdiff(names(y), names(x))]) df3[order(names(df3))] } fun(df1, df2) Rui Barradas Em 07-02-2013 19:16, Rui Barradas escreveu: Hello, The following function will give what you