[R] Merging data.table and data.frame

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Wed May 14 08:04:02 CEST 2014


Works for me. Can you make a reproducible example [1] the way the 
footers of all emails on this list ask you to? The str and dput functions 
are very useful tools mentioned in the referenced article.

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

On Wed, 14 May 2014, Abhinaba Roy wrote:

> Hi Peter,
>
> Thanks for your reply, I tried to convert my data.table into a data.frame
> and then merging but I am getting the same error. But when I check the
> class of my previously data.table object it returns "data.frame".
>
>
> Any clue as to why this is happening?
>
> Regards
>
>
> On Tue, May 13, 2014 at 7:13 PM, peter dalgaard <pdalgd at gmail.com> wrote:
>
>>
>> On 13 May 2014, at 14:34 , Abhinaba Roy <abhinabaroy09 at gmail.com> wrote:
>>
>>> Hi R-helpers,
>>>
>>> I am trying the following code in R
>>>
>>>
>> merge(x=Master1,y=demo_dtls,by.x=c("ID_CASE","ts"),by.y=c("ID_CASE","TS_EVENT"))
>>>
>>> where,
>>>
>>> class(demo_dtls$TS_EVENT)
>>> [1] "POSIXct" "POSIXt"
>>> class(Master1$ts)
>>> [1] "POSIXct" "POSIXt"
>>>
>>> and
>>>
>>>> class(Master1)[1] "data.table" "data.frame"> class(demo_dtls)[1]
>> "data.frame"
>>>
>>>
>>> But I am getting the following error
>>>
>>> Error in merge.data.table(x = Master1, y = demo_dtls, by.x =
>> c("ID_CASE",  :
>>>  Can not match keys in x and y to automatically determine appropriate
>>> `by` parameter. Please set `by` value explicitly.
>>>
>>> Why am I getting this error?
>>
>> You are using merge.data.frame syntax for merge.data.table. The latter
>> knows about by=, but not by.x= and by.y= (so presumably you need to rename
>> variables in x or y).
>>
>> - Peter
>>
>>
>>> Any help will be appreciated
>>>
>>>
>>> --
>>> Regards
>>> Abhinaba Roy
>>>
>>>       [[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.
>>
>> --
>> Peter Dalgaard, Professor
>> Center for Statistics, Copenhagen Business School
>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>> Phone: (+45)38153501
>> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
>>
>>
>
>
> -- 
> Regards
> Abhinaba Roy
> Statistician
> Radix Analytics Pvt. Ltd
> Ahmedabad
>
> 	[[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.
>

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k



More information about the R-help mailing list