[R-sig-genetics] Problem: sampling with replacement in R

Bhuller, Ravneet ravneet.bhuller13 at imperial.ac.uk
Wed Jan 18 14:24:57 CET 2017


Dear All,

My microsatellite dataset has 38 populations with population sizes varying from 7 to 76 individuals.


To sample one individual randomly per population and estimate mean genetic diversity (mean allelic richness),  I have done the following:

obj<- seppop(niger.data.genind)

mySamp <- lapply(obj, function(x) x[sample(1:nrow(x$tab), 1)])

x1<- repool(mySamp)

mean(allel.rich(x1)$mean.richness, na.rm = TRUE)

This method works fine.



However, when I sample 2 or more individuals randomly with replacement per population, I get the following error:

mySamp <- lapply(obj, function(x) x[sample(1:nrow(x$tab), 7, replace= TRUE)])

## Warning: non-unique value when setting 'row.names': '0905'


## Error in `row.names<-.data.frame`(`*tmp*`, value = value): duplicate 'row.names' are not allowed

My goals are:

To sample one individual randomly per population with replacement and estimate mean genetic diversity (mean allelic richness)

Then sample two individuals randomly per population and estimate mean genetic diversity (mean allelic richness)

And repeat this until I sample 76 individuals randomly per population and estimate mean genetic diversity (mean allelic richness).

Please if anyone can guide me where I am doing wrong or how can I fix it?


Many thanks for your time,

Rav




	[[alternative HTML version deleted]]



More information about the R-sig-genetics mailing list