Hello, I'm trying to take a PPS systematic sample of a data set, and I've gotten stuck at the last point. I have selection numbers, and just need to pick out the units whose cumulative size are the least upper bounds of these numbers This is as close as I've gotten: selected<-array(dim=c(97,4)) for (i in 1:97){ selected[i,]<-data[which.min(data$X-selectionnumber[i]),] } The problem here is that I want to pick out the upper bound, not the minimizer (the data$X value could be larger than my selection number). Is there a good function in R that could easily replace the which.min, or a better way to approach this? Thanks! [[alternative HTML version deleted]]