> deLHM2 Assay2 Size.um. Male.Unmated. Female.Unmated. Male.Mated. Female.Mated. 1 LHm (L2) 1420 1 3 1 3 2 LHm (L2) 1365 4 1 2 3 3 LHm (L2) 1313 1 2 1 3 4 LHm (L2) 1262 2 4 0 1 5 LHm (L2) 1214 6 2 3 0 6 LHm (L2) 1167 3 8 3 3 7 LHm (L2) 1122 7 21 0 3 8 LHm (L2) 1079 4 10 3 0 9 LHm (L2) 1038 2 7 0 2 10 LHm (L2) 998 4 8 0 011 LHm (L2) 948 3 6 0 0
But how can we actually compare (in R), for instance, the weight of mated and unmated females from the sample? We could do contingency tables to see if the frequency of counts in the two groups, but what if we wanted to compare the mean "girth" of these two groups? You could tediously enter the size of each individual (e.g. for unmated females, 1420,1420,1420,1356,1313,1313 etc...), but there must be a better way
Here, I will show how we can use the rep() function
Where I will specifiy in the first parameter what values I want repeated, and then for the second how many times I want it repeated.
> deLHmFU <-rep(c(deLHM2$Size.um.),c(deLHM2$Female.Unmated.)) > deLHmFM <-rep(c(deLHM2$Size.um.),c(deLHM2$Female.Mated.)) > deLHmFU [1] 1420 1420 1420 1365 1313 1313 1262 1262 1262 1262 1214 1214 1167 1167 1167 1167 1167 [18] 1167 1167 1167 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 1122 [35] 1122 1122 1122 1122 1122 1122 1122 1079 1079 1079 1079 1079 1079 1079 1079 1079 1079 [52] 1038 1038 1038 1038 1038 1038 1038 998 998 998 998 998 998 998 998 948 948 [69] 948 948 948 948 > deLHmFM [1] 1420 1420 1420 1365 1365 1365 1313 1313 1313 1262 1167 1167 1167 1122 1122 1122 1038 [18] 1038 >
Now I could proceed with the correct analyses (in this case due to non-normality of distributions, a Mann-Whitney test and a Cliff's delta) to compare the two groups.
No comments:
Post a Comment