[R] Combining data.frames

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Sun Mar 20 02:51:09 CET 2022


Then show your code so we can focus on what you haven't yet figured out. Have you read the examples in the merge help page?

On March 19, 2022 6:23:02 PM PDT, Jeff Reichman <reichmanj using sbcglobal.net> wrote:
>Evening Tom
>
>Yest I've been playing with the merge function.  But haven't been able to
>achieve what I need. Could maybe the way to to and it might be my syntax
>
>-----Original Message-----
>From: Tom Woolman <twoolman using ontargettek.com> 
>Sent: Saturday, March 19, 2022 8:20 PM
>To: reichmanj using sbcglobal.net
>Cc: r-help using r-project.org
>Subject: Re: [R] Combining data.frames
>
>Have you looked at the merge function in base R?
>
>https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/merge
>
>
>On 2022-03-19 21:15, Jeff Reichman wrote:
>> R-Help Community
>> 
>> I'm trying to combine two data.frames which each containing 10 columns 
>> of which they each share two common fields. Here are two small test 
>> datasets.
>> 
>> df1 <- data.frame(date =
>> c("2021-1-1","2021-1-1","2021-1-1","2021-1-1","2021-1-1",
>> 
>> "2021-1-2","2021-1-2","2021-1-3","2021-1-3","2021-1-3"),
>>                   geo_hash =
>> c("abc123","abc123","abc456","abc789","abc246","abc123",
>>                                "asd123","abc789","abc890","abc123"),
>>                   ad_id =
>> c("a12345","b12345","a12345","a12345","c12345",
>>                             
>> "b12345","b12345","a12345","b12345","a12345"))
>> df2 <- data.frame(date =
>> c("2021-1-1","2021-1-1","2021-1-2","2021-1-3","2021-1-3"),
>>                   geo_hash =
>> c("abc123","abc456","abc123","abc789","abc890"),
>>                   event =
>> c("shoting","ied","protest","riot","protest"))
>> 
>> I'm trying to combine them such that I get a combined data.frames such 
>> as
>> 
>> date		geo_hash	ad_id		event
>> 1/1/2021	abc123		a12345		shoting
>> 1/1/2021	abc123		b12345
>> 1/1/2021	abc456		a12345		ied
>> 1/1/2021	abc789		a12345
>> 1/1/2021	abc246		c12345
>> 
>> Jeff
>> 
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see 
>> 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.
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list