Re: [R] how to merge within range?

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Sat, 14 May 2011 13:10:29 -0400

On May 14, 2011, at 9:16 AM, Ian Gow wrote:

> If I assume that the third column in data.frame.2 is named "val"
> then in
> SQL terms it _seems_ you want
>
> SELECT a.time, b.val FROM data.frame.1 AS a LEFT JOIN data.frame.2
> AS b ON
> a.time BETWEEN b.start AND b.end;
>
> Not sure how to do that elegantly using R subsetting/merge,

Huh? It's just two merge()'s (... once you fix the error in the example.)

-- 
David


> but you might
> try a package that allows you to use SQL, such as sqldf.
>
>
> On 5/14/11 8:03 AM, "David Winsemius" <dwinsemius_at_comcast.net> wrote:
>
>>
>> On May 14, 2011, at 8:12 AM, René Mayer wrote:
>>
>>> Hello,
>>> how can one merge
>>
>> And what happened when you typed:
>>
>> ?merge
>>
>>> two data frames when in the second data frame one column defines the
>>> start values
>>> and another defines the end value of the to be merged range.
>>> data.frame.1
>>> time ...
>>> 13
>>> 24
>>> 35
>>> 46
>>> 55
>>> ...
>>> data.frame.2
>>> start end
>>> 24 37 ?h? ?
>>> ...
>>>
>>> should result in this
>>> 13 NA
>>> 24 ?h?
>>> 35 ?h?
>>> 46 NA
>>> 55
>>> ?
>>
>> And _why_ would that be?
>>
>>
>>> thanks,
>>> René
>>>
>>> ______________________________________________
>>> 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.
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>> ______________________________________________
>> 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.
>
>
David Winsemius, MD West Hartford, CT ______________________________________________ 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.
Received on Sat 14 May 2011 - 17:16:28 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 14 May 2011 - 18:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive