Hi experienced R users,
It's kind of a simple thing.
I want to sum x
by Group.1
depending on one controllable variable.
I'd like to sum x
by grouping the first two rows when I say something like: number <- 2
If I say 3
, it should sum x
of the first three rows by Group.1
Any idea how I might tackle this problem? Should I write a function? Thank y'all in advance.
Group.1 Group.2 x
1 1 Eggs 230299
2 2 Eggs 263066
3 3 Eggs 266504
4 4 Eggs 177196