[R] range and intersection

David Winsemius dwinsemius at comcast.net
Sun Mar 14 05:21:48 CET 2010


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



More information about the R-help mailing list