On 01/15/2010 01:49 AM, Bart Joosen wrote:
> 
> One way could be to first select only the unique ID's, sample this and then
> select only the relevant records:
> 
> strQuery = "SELECT ID from tblFoo;"
> IDs <- sqlQuery(channel, strQuery)
> sample.IDs <- sample(IDs,10)
> strQuery = paste("SELECT ID from tblFoo WHRE ID IN(", sample.IDs, ");")
> IDs <- sqlQuery(channel, strQuery)

Better is to use the built-in random() function in Postgres:

#select count(*) from visits;
  count
---------
 4846604
(1 row)

# select count(*) from visits where random() < 0.005;
 count
-------
 24391
(1 row)

HTH,

Joe

Attachment: signature.asc
Description: OpenPGP digital signature

______________________________________________
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.

Reply via email to