R/sample_methods.R

setMethod("sample", "data.frame", function (x, size, replace = FALSE, prob = NULL){
    if (missing(size))
        size <- nrow(x)
    ii <- sample.int(nrow(x), size, replace, prob)
    x[ii,,drop=FALSE]
})

setMethod("sample", "data.set", function (x, size, replace = FALSE, prob = NULL){
    if (missing(size))
        size <- nrow(x)
    ii <- sample.int(nrow(x), size, replace, prob)
    x[ii,,drop=FALSE]
})

setMethod("sample", "importer", function (x, size, replace = FALSE, prob = NULL){
    if (missing(size))
        size <- nrow(x)
    ii <- sample.int(nrow(x), size, replace, prob)
    x[ii,,drop=FALSE]
})

Try the memisc package in your browser

Any scripts or data that you put into this service are public.

memisc documentation built on May 2, 2019, 5:45 p.m.