[R] how to calculate a table

Bernd Dittmann herrdittmann at yahoo.co.uk
Mon Apr 12 06:17:49 CEST 2010


Hi R-Group,

I am stuck with the following problem: I am constructing a portfolio of
2 variables x and y 

x <- rnorm(100, mean=100, sd=4)
y <- rnorm(100, mean=120, sd=10)

which I am combining as follows to a portfolio for sampling purposes:

portfolio <- c(rep(x, 8), rep(y, 2))

In this case I have assigned the weights of 8 and 2 to calculate the
bootstrapped mean:

mean.boot <- function(z){
mean(sapply(lapply(1:20, function(i)sample(z, replace=F, size=30)),
mean))}

So far so good. But how can I bring it into table-form whereby the
combination of all 10 different weights (setting steps as 1) and their
respective bootstrapped means are printed:

weights		mean.boot
1		....
2		....
...		....
10		....

How can I do this?

Any suggestions most welcome.

Many thanks!

Bernd



More information about the R-help mailing list