I'm trying to use dplyr to summarize a dataframe of bird species abundance in forests which are fragmented to some degree.
The first column, percent_cover, has 4 possible values: 10, 25, 50, 75. Then there are ten columns of bird species counts: 'species1' through 'species10'.
I want to group by percent_cover, then sum the other columns and calculate these sums as a percentage of the 4 row sums.
To get to the column sums is easy enough:
%>% group_by(Percent_cover) %>% summarise_at(vars(contains("species")), sum)
...but what I need is sum/rowSum*100. It seems that some kind of 'rowwise' operation is needed.
Also, out of interest, why does the following not work?
%>% group_by(Percent_cover) %>% summarise_at(vars(contains("species")), sum*100)
At this point, it's tempting to go back to 'for' loops....or Excel pivot tables.