I have this dataframe:
sp rd pH abund area point
dog uniq 4.5 5 1 a
dog uniq 4.2 5 1 a
dog for 6.1 3 1 a
cat uniq 7.0 8 1 a
cat uniq 4.9 5 1 a
cat mains 3.1 9 1 b
cat mains 6.5 1 1 b
cat mains 6.5 3 1 b
dog for NA 2 2 a
bird mac 5.0 3 2 a
bird mac 4.1 5 2 a
bird mac 5.1 NA 2 a
rabb lol 5.0 8 2 b
rabb lol 4.2 5 2 b
rabb lol 6.0 2 2 b
rabb lol 2.8 3 2 b
In this dataframe, there are unique combinations of area
and point
, which are places. In this places there are animals defined by sp
and rd
. My goal is to get a list of vector, where each vector is sum of abund
of sp
within each place. In this case first vector of my list should be (13,13) because in place 1
a
there are three dogs whith abund
5+5+3 and two cats with abund
8+5.
My idea of solution was to divide my dataframe into groups (places) and within those sub-dataframes do the aggregate. But problem is, when I split
this dataframe into smaller ones, those dataframe will loose names
(each dataframe has only name of its combination, for example 1a) so I cant apply the aggregate
function.