Skip to content
Prev 439 / 1559 Next

dbSendPreparedQuery in RSQLite

Okay, well I thought that what I was doing was not easily done with  
one query but since I am wrong more often than not I'll ask and see if  
anyone can think of a way to combine it into one query.

I have a set of regions:

regions <- cbind(chr = c(1,2,3), start = c(1,230,4950), end = c(293,  
320, 19200))

In the db I have the following table:

CREATE TABLE count_table (chr, location, count);

chr location count
1	10		1
1	290		10
2	245		3
3	10		2

The query that I am using is:

apply(regions, 1, function(region) {
	paste("SELECT * FROM count_table WHERE chr =", region[1], "AND  
location >=", region[2],  "AND location <=", region[3], ";")
})

Which gives me back the following (which is exactly what I want):
[[1]]
   chr location count__1
1   1       10        1
2   1      290       10

[[2]]
   chr location count__1
1   2      245        3

[[3]]
NULL data frame with 0 rows


So I don't see any obvious way to pass in multiple ranges, but maybe I  
missing something with using the IN operator, thanks in advance, sorry  
for the long email.


Jim
On Apr 16, 2008, at 8:47 AM, Sean Davis wrote: