Skip to content
Prev 142 / 490 Next

Genuine object repooling issue

Hi,

You've got the right idea with make.unique, but you're trying to use repool on only one population at a time. 

First and foremost: don't use row.names(x$tab) or nrow(x$tab), use indNames(x) and nInd(x), respectively.


Your procedure needs to be done in three steps:

1. sample the individuals
2. rename the individuals
3. repool the populations

Taking the example you gave, this should work:

MySamp8 <- lapply(obj, function(x) x[sample(nInd(x), 8, replace= TRUE)])
MySamp8 <- lapply(MySamp8, function(x){ indNames(x) <- make.unique(indNames(x)); return(x)})
repool(MySamp8)


Here it is using a custom function:

sample_genind_with_replacement <- function(x, n = 8){
  y <- x[sample(nInd(x), n, replace = TRUE)]
  indNames(y) <- make.unique(indNames(y))
  return(y)
}
MySamp8 <- lapply(obj, sample_genind_with_replacement, n = 8)
repool(MySamp8)


Best,
Zhian