[R] range and intersection

Adrian Johnson oriolebaltimore at gmail.com
Sun Mar 14 06:05:19 CET 2010


The example I gave was just an example, I made for illustrating my problem. I


IF File1$Name == File2$Name then:
      check if File1$X is in range of File2$(x,y):
            if yes:
                 print File1$Name '\t' File1$X  '\t'  File2$Name '\t'
File2$X '\t' File2$Y
            if no :
                   Do nothing.

I am only interested in lines that match names in File2 to be printed.

I did this in Python but it is far slower.

thanks
Adrian


On Sat, Mar 13, 2010 at 11:55 PM, David Winsemius
<dwinsemius at comcast.net> wrote:
>
> On Mar 13, 2010, at 11:38 PM, Adrian Johnson wrote:
>
>> Hi David,
>> Sorry. I want to test  those lines in file1 match name in file2.
>>
>> IF File1$Name == File2$Name then:
>>      check if File1$X is in range of File2$(x,y):
>
> Not an adequately specific bit os pseudo code.
>
>>            if yes:
>>                 print File1$Name '\t' File1$X  '\t'  File2$Name '\t'
>> File2$X '\t' File2$Y.
>>
>
> So your example only provides three rows that should be considered, the ones
> with Name, "UK", right? What do you expect as a result? Obviously row 3
> won't be in any of the ranges, but 199 is in range for row 2 for file2 and
> 230 is also in range for row 2 in file2.
>
>>
>> Thanks
>> Adrian
>>
>>
>>
>> On Sat, Mar 13, 2010 at 11:21 PM, David Winsemius
>> <dwinsemius at comcast.net> wrote:
>>>
>>> On Mar 13, 2010, at 10:14 PM, Adrian Johnson wrote:
>>>
>>>> Hi:
>>>>
>>>> I have a two large files (over 300K lines).
>>>>
>>>> file 1:
>>>>
>>>> Name    X
>>>> UK       199
>>>> UK       230
>>>> UK       139
>>>> ......
>>>> UAE    194
>>>> UAE     94
>>>>
>>>>
>>>>
>>>>
>>>> File 2:
>>>>
>>>> Name   X    Y
>>>> UK    140   180
>>>> UK    195    240
>>>> UK    304    340
>>>> ....
>>>>
>>>
>>> I haven't figured out what you are expecting. Cannot tell whether you
>>> want
>>> to make this test a) all file1$X within values of "Name" or b) all
>>> file1$X
>>> across all values, or c) to pick a specific line in file1, or d) file1$X
>>>  on
>>> a line by line basis in file2. This implements that last of those three
>>> and
>>> has the downside of generating warnings.
>>>
>>>> file1[file2[, "X"] < file1[, "X"] & file1[, "X"] < file2[,"Y"], ]
>>>
>>>  Name   X
>>> 2   UK 230
>>> Warning messages:
>>> 1: In file2[, "X"] < file1[, "X"] :
>>>  longer object length is not a multiple of shorter object length
>>> 2: In file1[, "X"] < file2[, "Y"] :
>>>  longer object length is not a multiple of shorter object length
>>>
>>>>
>>>> I want to select X of File 1 and search if it falls in range of X and
>>>> Y of File 2 and Print only those lines of File 1 that are in range of
>>>> File 2 X and Y
>>>>
>>>>
>>>> How can it be done it in R.
>>>>
>>>> thanks
>>>> Adrian
>>>>
>>>> ______________________________________________
>>>> 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
>>>
>>>
>
> David Winsemius, MD
> West Hartford, CT
>
>



More information about the R-help mailing list