[R] merge 2 data.frames in dependence of 2 values

Michael Dewey info at aghmed.fsnet.co.uk
Thu Nov 13 18:24:35 CET 2014



On 13/11/2014 14:02, Matthias Weber wrote:
> Hello togehter,
>
> i have a little problem. Maybe anyone can help me.

I think you might find
?merge
enlightening

Indeed given that the word merge occurs in your subject line and your 
text it is surprising you have not already found it.

>
> I have 2 data.frames, which look like as follows:
> First:
>
>          NAME    MONTH     BONUS
> 1      Andy     2014-10       100
> 2      Pete     2014-10        200
> 3      Marc    2014-10        300
> 4      Andy    2014-11        400
>
> Second:
>
>        NAME  MONTH    BONUS_2
> 1    Andy    2014-10       150
> 2    Pete     2014-11       180
> 3    Jason   2014-10       190
> 4    Paul     2014-10       210
> 5    Andy    2014-11       30
>
> How can I merge this 2 data.frames, if I want the following result:
>
>          NAME    MONTH     BONUS    BONUS_2
> 1     Andy     2014-10       100            150
> 2     Pete     2014-11                         180
> 3     Marc    2014-10        300
> 4     Andy    2014-11       400             30
> 5     Pete     2014-10       200
> 6     Jason  2014-10                         190
> 7     Paul     2014-10                         210
>
> The important thing is, that for every accordance in the Columns "NAME" and "MONTH" I get a new line.
>
> Thanks for your help.
>
> Best regards.
>
> Mat
>
> ________________________________
> This e-mail may contain trade secrets, privileged, undisclosed or otherwise confidential information. If you have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal. Thank you for your cooperation.
>
> Diese E-Mail kann Betriebs- oder Geschaeftsgeheimnisse oder sonstige vertrauliche Informationen enthalten. Sollten Sie diese E-Mail irrtuemlich erhalten haben, ist Ihnen eine Kenntnisnahme des Inhalts, eine Vervielfaeltigung oder Weitergabe der E-Mail ausdruecklich untersagt. Bitte benachrichtigen Sie uns und vernichten Sie die empfangene E-Mail. Vielen Dank.
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2015.0.5557 / Virus Database: 4213/8566 - Release Date: 11/13/14
>
>

-- 
Michael
http://www.dewey.myzen.co.uk



More information about the R-help mailing list