如何对列中的值求和,按R中的行中的名称分组,而不列出每个名称?

Kim*_*Kim 4 aggregate r

如何使用R来查找物种的值总和?我有62种名称,并希望在栖息地中添加每个物种的基础面积.我试过了

aggregate(file name, species, FUN=sum, simplify=TRUE)
Run Code Online (Sandbox Code Playgroud)

以及它的许多变化,但它总是说它找不到species(我的数据集中的列标题).列表太长,无法添加为输入; 我希望程序使用我的列信息.我的数据集看起来像这样:

Species      BA
sp1          0.5
sp1          0.2
sp2          0.1
Run Code Online (Sandbox Code Playgroud)

Mat*_*erg 5

首先将数据读入数据帧,然后使用聚合.

# You would read from the file instead.
x <- read.table(header=T, file=textConnection("Species      BA
sp1          0.5
sp1          0.2
sp2          0.1
"))

> aggregate(.~Species, data=x, FUN=sum)
  Species  BA
1     sp1 0.7
2     sp2 0.1
Run Code Online (Sandbox Code Playgroud)