Skip to content
Prev 128 / 490 Next

Suggestions regarding randomly repooling genind objects

Hi,

The function repool() can take a list object, and you can subset a list with replacement. The sample() function will allow you to randomly sample any vector with or without replacement. 

For this problem, you should only need one loop/apply function.

Here's an example:

library(adegenet)
data(nancycats)
nanpop <- seppop(nancycats, drop = FALSE)
repooled <- lapply(seq(2, nPop(nancycats)), function(n) repool(nanpop[sample(17, n)]))

In the end, this will give you a list of repooled genind objects where each genind object only contains unique populations and the last object is the same size as the original, but in a different order. If you wanted the potential for duplicate populations within your data, you would add replace = TRUE to the sample() function. 

Hope that helps,
Zhian