[R] group definition for a bootstrap

Louize Hill lhill at ipimar.pt
Mon Jul 26 16:06:50 CEST 2004


Hi,
This is probably really simple, but I am clearly not R-minded, I have read
the help files, and reread them, and I still can't work out what to do...
I have a data frame (d) with 3 columns (age (0-5), quarter (1-4) and x).
I want to estimate the precision of my mean x by age and quarter, so I want
to carry out a bootstrap for each group.
I am trying to do this within a loop, so I don't have to retype the whole
thing out 20 times ...
This is what I have done:

n = length (d$x)
N = 1000
stat = numeric(N)
for (i in 1:N) {
d$x2 = sample (d$x, n, replace=T)
stat[i] = mean(d$x2)
}

I believe I should define the age and quarter groups in the line straight
after "for" - using the split function, or should I use some variant of
[d$age == "1" & d$quarter =="1"] in the sample definition?
Please don't think I am looking for an easy answer - I have been puzzling
for this for over a week already :(
(I am using R1.9 under MS W2000)
Thank you in advance
Louize




More information about the R-help mailing list