If you also want to match on the Name, this should do it: > file1 <- read.table(textConnection("Name X + UK 199 + UK 230 + UK 139 + UAE 194 + UAE 94"), header=TRUE, as.is=TRUE) > file2 <- read.table(textConnection("Name X Y + UK 80 100 + UK 140 180 + UK 195 240 + UK 304 340 + UAE 100 150 + UAE 190 200"), header=TRUE, as.is=TRUE) > closeAllConnections() > # initial the 'match' to FALSE > file1$match <- FALSE > > # if you want to match on the Name in file2 to pickout the subset of ranges, > # loop through the rows of file2 making the test (assuming it is the shorter file) > for (i in seq(nrow(file2))){ + file1$match <- file1$match | ( + (file1$X >= file2$X[i]) & + (file1$X <= file2$Y[i]) & + (file1$Name == file2$Name[i])) + } > > file1 Name X match 1 UK 199 TRUE 2 UK 230 TRUE 3 UK 139 FALSE 4 UAE 194 TRUE 5 UAE 94 FALSE
On Sat, Mar 13, 2010 at 11:29 PM, jim holtman <jholt...@gmail.com> wrote: > Try this: > > > file1 <- read.table(textConnection("Name X > + UK 199 > + UK 230 > + UK 139 > + UAE 194 > + UAE 94"), header=TRUE, as.is=TRUE) > > file2 <- read.table(textConnection("Name X Y > + UK 140 180 > + UK 195 240 > + UK 304 340"), header=TRUE, as.is=TRUE) > > closeAllConnections() > > # initial the 'match' to FALSE > > file1$match <- FALSE > > # loop through the rows of file2 making the test (assuming it is the > shorter file) > > for (i in seq(nrow(file2))){ > + file1$match <- file1$match | ((file1$X >= file2$X[i]) & (file1$X <= > file2$Y[i])) > + } > > > > file1 > Name X match > 1 UK 199 TRUE > 2 UK 230 TRUE > 3 UK 139 FALSE > 4 UAE 194 FALSE > 5 UAE 94 FALSE > > > On Sat, Mar 13, 2010 at 10:14 PM, Adrian Johnson < > oriolebaltim...@gmail.com> 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 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@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<http://www.r-project.org/posting-guide.html> >> and provide commented, minimal, self-contained, reproducible code. >> > > > > -- > Jim Holtman > Cincinnati, OH > +1 513 646 9390 > > What is the problem that you are trying to solve? > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] ______________________________________________ R-help@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.