[R] boot&table

Mpiktas mpiktas at delfi.lt
Fri Nov 8 13:02:24 CET 2002


> I want to bootstarp a sample, and I need table() for each sample taken,
> like if R=100, I need all 100 table(). It seems to mee that boot() works
> anly if you assing statistics, that gives you back one number, like
> mean. Although the ?boot/statistics says that it can be a vector
> containing statistics. table() gives an array, so it might work. Does
> anybody have an idea how? I konw it can be done by a loop and
> sample() function, but it not as fast as boot().

I am not sure what do you want to do. Function boot needs data as 
vector, matrix, or data.frame. Boot does work with statistics, which 
gives back vector. Give more details, why can't you work with matrix or 
data.frame instead of table.

> Another question, how can you get frequencies for sample values, like what
> table() does, but with reference to both the value itself and the
> corresponding frequencies. I would like to have those values in a matrix
> with 2 col. It is very troublesome to make it form what table() returns.

table2matrix <-
function (x) {
     if (!is.table(x)) {
        stop("I need table")
     mm <- cbind(as.numeric(names(x)),x)
     rownames(mm) <- NULL
Or some other way, it is just an example. As you see, nothing very 


r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list