s-news
[Top] [All Lists]

Re: merge of data frame

To: asanquer@virbac.fr
Subject: Re: merge of data frame
From: Chuck Cleland <ccleland@optonline.net>
Date: Thu, 17 Jul 2003 04:52:41 -0400
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <OF8B2CA803.85AC674E-ONC1256D66.002A4FE0-C1256D66.002B3D9B@virbac.fr>
References: <OF8B2CA803.85AC674E-ONC1256D66.002A4FE0-C1256D66.002B3D9B@virbac.fr>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4b) Gecko/20030507
Annaële:

Notice the "all" argument in ?merge. You probably want the following:

> newDF <- merge(DF1, DF2, all=T)
> newDF

   ID X1 X2
 1  1  T  F
 2  2  F NA
 3  3  F  F
 4  4  T  T
 5  5  T NA
 6  6  F  F
 7  7  F NA
 8  8  T NA
 9  9  F NA
10 10  F NA

hope this helps,

Chuck Cleland

asanquer@virbac.fr wrote:
I have two data frame:

DF1:
id    X1
1     T
2     F
3     F
4     T
...
10    T

DF2:
id    X2
1     F
3     F
4     T
6     F

If I use DF3 <- merge(DF1,DF2), I obtain a data frame with only 4
observations (id=1,3,4,6).
But I would like to have a data frame with the 10 observations (id=1 to 10)
and X2 values equal to NA for id=2,5,7,8,9,10.


<Prev in Thread] Current Thread [Next in Thread>