title: Sum of last order and average cost over all orders
body: <p>Data:</p>
  
  <pre><code>DB &lt;- data.frame(orderID  = c(1,2,3,4,5,6,7,8,9,10),     
  orderDate = c("1.1.14","1.1.14","1.1.14","1.1.14","1.1.14", "1.1.14","1.1.14","2.1.14","2.1.14","2.1.14"),  
  itemID = c(2,3,2,5,12,4,2,3,1,5),  
  price = c(29.90, 39.90, 29.90, 19.90, 49.90, 9.90, 29.90, 39.90, 14.90, 19.90),
  customerID = c(1, 2, 3, 1, 1, 3, 2, 2, 1, 1))
  </code></pre>
  
  <p>Expected outcome: </p>
  
  <pre><code>orderValueOfLastOrder = c(34.80, 39.90, 39.80, 34.80, 34.80, 39.80, 39.90, 39.90, 34.80, 34.80) 
  AverageValue = c(67.25, 54.85, 39.80, 67.25, 67.25, 39.80, 54.85, 54.85, 67.25, 67.25)
  </code></pre>
  
  <p>Hi,
  I got a problem to solve in r for my boss, so I would be very pleased if you peeps help me :)
  In the data set every order got its own id and every registered user has his unique customerID. Every customer can order items (with ItemIDs), which got specific prices.
  I want to sum the prices for the orders, but I had 2 problems:
  1. I wanted the value(sum) of the last order for every customer ((sum up the prices of all ordered Items from last order for every user[the date today is for example the 15.10.14])
  2. The average price per order[for his orders] for every user<br>
  I also want to add the results as new columns in my existing data set...</p>
  
  <p>I tried it already with:</p>
  
  <pre><code>DB1$orderValueOfLastOrder&lt;- with(DB1, ave(as.numeric(DB1$orderDate), 
  price, FUN = function(x) sum(x ==max(x)))) 
  </code></pre>
  
  <p>but it´s not working...</p>
  
  <p>so can you please show me a way to do it with "ave" function[I prefer to do it with ave (if this is not possible I would be very happy with every other solution, too :) ) </p>
  
  <p>Thanks a lot for your support!</p>