[S] How to do a "one-to-many merge" in SPlus?

John Oehlert (joehlert@leland.stanford.edu)
Wed, 16 Sep 1998 08:42:51 -0700

Hi All,

I am bootstrapping a patient dataset containing approx. 400 patients each
having anywhere from 2 to 9 "visits". Because the number of visits is not
the same for all patients the resulting bootstrap dataset have a varying #
of visits from 700 to just over a 1000. I could not see how to use any of
the canned bootstrap routines to sample patients with replacement and then
reconstruct a visit dataset so I did it myself using a list of unique
patient identifiers and the sample() funtion. This was a piece of cake.
(However, if anyone can show me how to do this with one of the standard
bootstrap routines I w/not complain!)

My difficulty came when I tried to take this list of patients and
reconstruct the bootstrap "visit" dataset. I could not get SPlus to take
each patient in the new patient list and pull all visits for that patient
from the visit file....and do this for as many times as the patient appears
in the patient list. I finally gave up and crunched the problem using a for
loop and rbind(). I know this sort of loop is very costly re: time and
w/like to learn a more efficient way to do this task. I have included the
loop structure below. Perhaps someone can tell me how a real SPlus wiz w/go
about this.

Thanks in advance.

# B = the # of bootstrap replicates to create.;


replicates_matrix(nrow=size, ncol=B);

# 6 is the length of the output vector from max.knots;

for(r in 1:B) {
print(paste("Starting B=",r));
replicate_sort(sample(id.list, size=size, replace=T));
new.dsn_matrix(nrow=1, ncol=dim(in.dsn)[2], NA);
for(rep.number in 1:size) {
if(rep.number==1) new.dsn_new.pat else new.dsn_rbind(new.dsn,new.pat);
knots[r,]_max.knot(run.knots(new.dsn, MinKnot=Min.Knot,

Thanks again to all!


John Oehlert
Statistical Programmer/Systems Analyst
Division of Biostatistics
HRP Redwood Building, Rm T100
Stanford, California 94305-5405

Voice: (650) 725-2925
Fax: (650) 725-6951
Email: joehlert@leland.stanford.edu

This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news