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 March 31, 2023, 7:29 p.m.