More work on resample.R