sample-methods | R Documentation |
This method samples rows of data from a table/view randomly. The sampled result is stored in a temporary table.
## S4 method for signature 'db.obj'
sample(x, size, replace = FALSE, prob = NULL, ...)
x |
A |
size |
An integer. The size of the random sample. When |
replace |
A logical value, default is |
prob |
A vector of double values, default is |
... |
Extra parameters. Not implemented. |
When replace
is FALSE
, the data is just sorted randomly
(see sort,db.obj-method
) and selected, which is similar
to sort(x, FALSE, "random")
. When
replace
is TRUE
, we have to scan the table multiple
times to select repeated items.
A db.data.frame
object, which is a wrapper to a
temporary table. The table contains the sampled data.
Author: Predictive Analytics Team at Pivotal Inc.
Maintainer: Frank McQuillan, Pivotal Inc. fmcquillan@pivotal.io
## Not run:
## set up the database connection
## Assume that .port is port number and .dbname is the database name
cid <- db.connect(port = .port, dbname = .dbname, verbose = FALSE)
y <- as.db.data.frame(abalone, conn.id = cid, verbose = FALSE)
lk(y, 10)
dim(y)
a <- sample(y, 20)
dim(a)
lookat(a)
b <- sample(y, 40, replace = TRUE)
dim(b)
lookat(b)
delete(b)
db.disconnect(cid, verbose = FALSE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.