I have a matrix of counts, spp.mat, with 5 columns and 100 rows that looks like this:
n.samp <- 100
n.spp <- 5
spp.vec <- list()
for(i in 1:n.spp){
spp.vec[[i]] <- round(runif(n.samp,0,200))
}
spp.mat <- do.call(cbind, spp.vec)
For each row in the matrix, I would like to randomly sample 20 observations without replacement, and store that in a new matrix. So, rowSums(new.matrix) would equal 20. I've considered converting the rows to probabilities, as spp.prb <- spp.mat/rowSums(spp.mat) and drawing from a multinomial distribution 20 times, however, this is not suitable for the problem I am trying to solve. For example, if an entry in a row is 1, it is important that it is drawn no more than 1 time in the subsample.
Aucun commentaire:
Enregistrer un commentaire