在R中对生态数据进行分组 [英] Grouping ecological data in R

查看:86
本文介绍了在R中对生态数据进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看一些生态数据(饮食),试图找出如何按捕食者分组.我希望能够提取数据,以便可以查看每个捕食者对每个物种的每个猎物的权重,即算出被捕食者117等所食用的每种物种的平均权重.我下面的数据.

I'm looking at some ecological data (diet) and trying to work out how to group by Predator. I would like to be able to extract the data so that I can look at the weights of each individual prey for each species for each predator, i.e work out the mean weight of each species eaten by e.g Predator 117. I've put a sample of my data below.

   Predator PreySpecies PreyWeight
1   114      10    4.2035496
2   114      10    1.6307026
3   115       1   407.7279775
4   115       1   255.5430495
5   117      10    4.2503708
6   117      10    3.6268814
7   117      10    6.4342073
8   117      10    1.8590861
9   117      10    2.3181421
10  117      10    0.9749844
11  117      10    0.7424772
12  117      15    4.2803743
13  118       1   126.8559155
14  118       1   276.0256158
15  118       1   123.0529734
16  118       1   427.1129793
17  118       3   237.0437606
18  120       1   345.1957190
19  121       1   160.6688815

推荐答案

您可以按以下方式使用aggregate函数:

You can use the aggregate function as follows:

aggregate(formula = PreyWeight ~ Predator + PreySpecies, data = diet, FUN = mean)

#   Predator PreySpecies PreyWeight
# 1      115           1 331.635514
# 2      118           1 238.261871
# 3      120           1 345.195719
# 4      121           1 160.668881
# 5      118           3 237.043761
# 6      114          10   2.917126
# 7      117          10   2.886593
# 8      117          15   4.280374

这篇关于在R中对生态数据进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆