dpylr, , , aggregate(), :
aggregate(cbind(Buys = Buy, Sells = !Buy,
Price_Buys = Price * Buy, Price_Sells = Price * !Buy) ~ Date,
data = dat, sum)
#
#
#
The idea here is to get sales like !Buy. This converts Buyto logical (0 => TRUE, 1 => FALSE), and then applies the NOT-operator (!) To it. Thus, 0 is converted to 1 and 1 is converted to 0. The same trick can be used in pricing.
Comparing this solution with others should also show you what dplyrcreates much more readable code.
Stibu source
share