jeudi 22 juillet 2021

Random subsampling of a data.frame and summarize mean and standard deviation

In R, I have some ecological data in this form:

sample = seq(1, 20, by=1)

group = c("A","A","A","B","B","C","D","E","E","E","E","E","E",
          "E","E","E","E","F","F","F")

df = data.frame(sample, group)

Where sample is the sample number and group is a different taxonomic group associated with each sample

In total, I have 20 samples (in reality more) and I can get the relative frequency of a certain group with:

data.frame(table(group)/length(group))

group Freq
1     A 0.15
2     B 0.10
3     C 0.05
4     D 0.05
5     E 0.50
6     F 0.15

Now I would like to subsample (10 samples) my data frame for 100 times and get the mean relative frequency of each group together with the standard deviation.

How can I do that?




Aucun commentaire:

Enregistrer un commentaire