Categories
Easy Sumif in R Using The Aggregate Function
This is a really simple (i.e. probably even the most basic possible) example of using the built in aggregate() function in R, basically a sumif in R.
Given a set of data where column a is the values and column b contains the data by which you wish to group (in this example categorical data with values of a or b):
> data
a b
1 0 a
2 0 a
3 1 b
4 2 a
5 2 b
6 2 a
7 3 b
8 4 b
9 7 b
The aggregate function as I have used it below takes the following arguments -- data$a is the Read more [...]