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

> On Jan 19, 2017, at 07:50 , Bhuller, Ravneet 
> <[email protected]> wrote:
> 
> Dear Members,
> 
> I am working with a genind object which is subset into populations. I want to 
> sample 8 individuals randomly with replacement per population and repool them 
> in a way that each population has unique individual names.
> 
> I am doing the following steps:
> 
> obj<- seppop(niger.data.genind)
> 
> MySamp8 <- lapply(obj, function(x) x[sample(1:nrow(x$tab), 8, replace= TRUE)])
> 
> new_samp8<- lapply(MySamp8, function(x) 
> repool(MySamp8[make.unique(row.names(x$tab))]))
> 
> But I am getting the following error:
> 
> Error in repool(MySamp8[make.unique(row.names(x$tab))]): x is does not 
> contain only valid genind objects.
> 
> Please if any one can guide me how can I get valid genind objects to repool 
> them in a way that each population has unique individual names.
> 
> Many thanks for your time,
> 
> Rav
> 
>       [[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-genetics mailing list
> [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-genetics

_______________________________________________
R-sig-genetics mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-genetics

Reply via email to