[R] Merging multiple data sets
Sarah Goslee
sarah.goslee at gmail.com
Thu Jun 23 19:02:24 CEST 2011
Hi,
> How can I best do this in R? I've looked into merge but it excludes ids that
> aren't in all 3 data sets.
You need to look a bit harder at merge(), specifically the all.x and
all.y options.
Sarah
On Thu, Jun 23, 2011 at 12:53 PM, cddesjar <cddesjardins at gmail.com> wrote:
> Hi,
> I am trying to merge data similar to the example data below
>
>> dat0
>
> id var1 var2 var3
> 2 1 0 1
> 3 1 0 1
> 4 0 1 1
> 5 0 1 1
>
>> dat1
>
> id var4 var5 var6
> 2 1 0 1
> 3 1 0 1
> 6 0 1 1
> 7 0 1 1
>
>> dat2
>
> id var7 var8 var9
> 2 1 0 1
> 5 1 0 1
> 6 0 1 1
> 8 0 1 1
>
> Basically what I'd like to do is combine these variables on id and create
> one large data frame that looks like the following.
>
>> dat3
>
> id var1 var2 var3 var4 var5 var6 var7 var8 var9
> 2 1 0 1 1 0 1 1 0
> 1
> 3 1 0 1 1 0 1 NA NA
> NA
> 4 0 1 1 NA NA NA NA NA NA
> 5 0 1 1 NA NA NA NA NA NA
> 6 NA NA NA 0 1 1 0 1 1
> 7 NA NA NA 0 1 1 NA NA NA
> 8 NA NA NA NA NA NA 0 1 1
>
> How can I best do this in R? I've looked into merge but it excludes ids that
> aren't in all 3 data sets.
>
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list