This should be theoretically very simple, but I dont get the elegant answer (without looping). I've got a long (thousands of rows) data frame:> E.coor[1:10,]east north dat 1 582650 4248850 0.8316848 2 582750 4248850 0.7230272 3 582850 4248850 0.3250818 4 582950 4248850 0.6144006 5 583050 4248850 0.8706312 6 583150 4248850 0.2149651 7 583250 4248850 0.1659519 8 583350 4248850 0.2145174 9 583450 4248850 0.1615151 10 583550 4248850 0.9370766 and need to extract those with the coordinates coinciding with those in a smaller data frame (about one hundred rows):> subset.cooreast north 20 584550 4248850 21 584650 4248850 22 584750 4248850 23 584850 4248850 24 584950 4248850 25 585050 4248850 i.e, I need the ~ one hundred E.coor rows that appear in subset.coor Could you help with this. Best regards, Javier ---------
?merge> E <- read.table(textConnection(" east north dat+ 1 582650 4248850 0.8316848 + 2 582750 4248850 0.7230272 + 3 582850 4248850 0.3250818 + 4 582950 4248850 0.6144006 + 5 583050 4248850 0.8706312 + 6 583150 4248850 0.2149651 + 7 583250 4248850 0.1659519 + 8 583350 4248850 0.2145174 + 9 583450 4248850 0.1615151 + 10 583550 4248850 0.9370766"), header=TRUE)> sub <- read.table(textConnection(" east north+ 20 582650 4248850 + 21 583250 4248850 + 22 584750 4248850 + 23 584850 4248850 + 24 584950 4248850 + 25 585050 4248850"), header=TRUE)> closeAllConnections() > merge(E, sub, by=c('east', 'north'))east north dat 1 582650 4248850 0.8316848 2 583250 4248850 0.1659519>On Mon, Jun 23, 2008 at 12:32 PM, <jgarcia at ija.csic.es> wrote:> This should be theoretically very simple, but I dont get the elegant > answer (without looping). > > I've got a long (thousands of rows) data frame: > >> E.coor[1:10,] > east north dat > 1 582650 4248850 0.8316848 > 2 582750 4248850 0.7230272 > 3 582850 4248850 0.3250818 > 4 582950 4248850 0.6144006 > 5 583050 4248850 0.8706312 > 6 583150 4248850 0.2149651 > 7 583250 4248850 0.1659519 > 8 583350 4248850 0.2145174 > 9 583450 4248850 0.1615151 > 10 583550 4248850 0.9370766 > > and need to extract those with the coordinates coinciding with those in a > smaller data frame (about one hundred rows): > >> subset.coor > east north > 20 584550 4248850 > 21 584650 4248850 > 22 584750 4248850 > 23 584850 4248850 > 24 584950 4248850 > 25 585050 4248850 > > i.e, I need the ~ one hundred E.coor rows that appear in subset.coor > > Could you help with this. > > > Best regards, > Javier > --------- > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
You can also do this:> E[(E$east %in% sub$east) & (E$north %in% sub$north),]east north dat 1 582650 4248850 0.8316848 7 583250 4248850 0.1659519>On Mon, Jun 23, 2008 at 12:32 PM, <jgarcia at ija.csic.es> wrote:> This should be theoretically very simple, but I dont get the elegant > answer (without looping). > > I've got a long (thousands of rows) data frame: > >> E.coor[1:10,] > east north dat > 1 582650 4248850 0.8316848 > 2 582750 4248850 0.7230272 > 3 582850 4248850 0.3250818 > 4 582950 4248850 0.6144006 > 5 583050 4248850 0.8706312 > 6 583150 4248850 0.2149651 > 7 583250 4248850 0.1659519 > 8 583350 4248850 0.2145174 > 9 583450 4248850 0.1615151 > 10 583550 4248850 0.9370766 > > and need to extract those with the coordinates coinciding with those in a > smaller data frame (about one hundred rows): > >> subset.coor > east north > 20 584550 4248850 > 21 584650 4248850 > 22 584750 4248850 > 23 584850 4248850 > 24 584950 4248850 > 25 585050 4248850 > > i.e, I need the ~ one hundred E.coor rows that appear in subset.coor > > Could you help with this. > > > Best regards, > Javier > --------- > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Here are two solutions: # 1 merge(subset.coor, E.coor) # 2 # note that we changed the names of the data frames # for this solution since dot is an operator in SQL library(sqldf) sqldf("select * from subset_coor natural join E_coor") On Mon, Jun 23, 2008 at 12:32 PM, <jgarcia at ija.csic.es> wrote:> This should be theoretically very simple, but I dont get the elegant > answer (without looping). > > I've got a long (thousands of rows) data frame: > >> E.coor[1:10,] > east north dat > 1 582650 4248850 0.8316848 > 2 582750 4248850 0.7230272 > 3 582850 4248850 0.3250818 > 4 582950 4248850 0.6144006 > 5 583050 4248850 0.8706312 > 6 583150 4248850 0.2149651 > 7 583250 4248850 0.1659519 > 8 583350 4248850 0.2145174 > 9 583450 4248850 0.1615151 > 10 583550 4248850 0.9370766 > > and need to extract those with the coordinates coinciding with those in a > smaller data frame (about one hundred rows): > >> subset.coor > east north > 20 584550 4248850 > 21 584650 4248850 > 22 584750 4248850 > 23 584850 4248850 > 24 584950 4248850 > 25 585050 4248850 > > i.e, I need the ~ one hundred E.coor rows that appear in subset.coor > > Could you help with this. > > > Best regards, > Javier > --------- > > ______________________________________________ > 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. >