Skip to content

Instantly share code, notes, and snippets.

@taddallas
Last active November 28, 2019 01:01
Show Gist options
  • Save taddallas/df5c6af9fe49e7b94de076bfd8a24483 to your computer and use it in GitHub Desktop.
Save taddallas/df5c6af9fe49e7b94de076bfd8a24483 to your computer and use it in GitHub Desktop.
Relative abundance does what now!?
# my "true community" (a census)
comm <- sample(as.factor(letters[1:5]), 1000,
prob=c(0.6,0.4,0.2,0.1,0.1), replace=TRUE)
# taking random samples from my community and calculating relative abundance
samps <- plyr::ldply(1:1000, function(x){
set.seed(x)
tmp <- table(sample(comm, 10))
tmp <- tmp/sum(tmp)
return(tmp)
})
# taking the mean of each relative abundance in the sample
colMeans(samps)
# I think I see what Andrew is saying!!!
rowMeans(samps)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment