You can build a spline curve using smooth.spline and lines :
plot.spline = function(x, y, ...) { s = smooth.spline(x, y, cv=TRUE) lines(predict(s), ...) }
So, in order to complete the download, in accordance with the instructions in the book, you produce random rows from the data with the replacement and call plot.spline on the re-selected data:
bootstrap.curves = function(dat, nboot, ...) { for (i in 1:nboot) { subdata = dat[sample(NROW(dat), replace=TRUE), ] plot.spline(subdata$age, subdata$spnbmd, ...) } }
Thus, you can use this function to run separate charts for men and women:
bootstrap.curves(dat2[dat2$gender == "female", ], 10, col="red") bootstrap.curves(dat2[dat2$gender == "male", ], 10, col="blue")
Final result:

Note. This code will generate a few warnings (not errors) that look like this:
1: In smooth.spline(x, y, cv = TRUE) : crossvalidation with non-unique 'x' values seems doubtful
This is due to re-fetching the bootstrap. smooth.spline uses cross-validation to determine the number of degrees of freedom to give a spline, but he prefers not to do this with duplicate x values (since there will always be a re-fetch bootstrap there). You can get around this by choosing your own number of degrees of freedom, but this is probably suitable for this purpose.