I am performing a bootstrap analysis of community similarity values. I have a matrix of species counts, where the columns represent unique samples, and the rows unique species. Here is an example:
#generate a matrix with 20 columns, 30 rows, random values
set.seed(69) #for reproducibility.
otu <-matrix(rpois(20*30, lambda = 2), ncol=20)
I have two vectors that are environmental covariates associated with the unique samples. Therefore, each of these vectors is length 20.
v1 <- rnorm(20)
v2 <- rnorm(20)
I want to create a new species observation matrix that randomly samples the columns of the otu matrix, with replacement. I can do this fairly easily.
#randomnly sample the columns of the otu matrix with replacement.
otu.boot <- otu[,sample(ncol(otu),size=ncol(otu),replace=TRUE)]
My question is, how can I sample vectors v1 and v2 in the same order as the randomly sampled with replacement matrix?
Aucun commentaire:
Enregistrer un commentaire