Skip to content
Prev 344148 / 398500 Next

To Add a variable from Df1 to Df2 which have a same common variable

On Sep 19, 2014, at 12:15 PM, Arnaud Michel <michel.arnaud at cirad.fr> wrote:

            
Hi,

Thanks for including data.

See ?merge, which performs an SQL-like join.

Since you have non-matching values between Df1 and Df2, you will need to decide if you want non-matching rows included in the resultant data frame or not (eg. a right/left outer or inner join). See the all, all.x and all.y arguments to merge(). 

The default (all = FALSE) is an inner join on matching rows only:

  Df3 <- merge(Df1, Df2, by = "AgeSexeCadNCad")

If you include non-matching values in the resultant data frame (eg. all = TRUE), Pourcent will contains NA's in those rows.

Regards,

Marc Schwartz