[R] combining dataframes with different numbers of columns
sundar.dorai-raj at pdf.com
Wed Nov 8 04:04:20 CET 2006
hadley wickham said the following on 11/7/2006 8:46 PM:
> On 11/7/06, Denis Chabot <chabotd at globetrotter.net> wrote:
>> Dear list members,
>> I have to combine dataframes together. However they contain different
>> numbers of variables. It is possible that all the variables in the
>> dataframe with fewer variables are contained in the dataframe with
>> more variables, though it is not always the case.
>> There are key variables identifying observations. These could be used
>> in a merge statement, although this won't quite work for me (see below).
>> I was hoping to find a way to combine dataframes where I needed only
>> to ensure the key variables were present. The total number of
>> variables in the final dataframe would be the total number of
>> different variables in both initial dataframes. Variables that were
>> absent in one dataframe would automatically get missing values in the
>> joint dataframe.
> Have a look at rbind.fill in the reshape package.
> rbind.fill(data.frame(a=1), data.frame(b=2))
> rbind.fill(data.frame(a=1), data.frame(a=2, b=2))
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Or, try this:
More information about the R-help