title: ratios according to two variables, function aggregate in R?
body: <p>I've been playing with some data in order to obtain the ratios between two levels within one variable and taking into account two other variables. I've been using the function <em>aggregate()</em>, which is very useful to calculate means and sums. However, I'm stuck when I want to calculate some ratios (divisions). 
  Here you find a dataframe very similar to my data: </p>
  
  <pre><code>w&lt;-c("A","B","C","D","E","F","A","B","C","D","E","F")
  x&lt;-c(1,1,1,1,1,1,2,2,2,2,2,2)
  y&lt;-c(3,4,5,6,8,10,3,4,5,7,9,10)
  z&lt;-runif(12)
  df&lt;-data.frame(w,x,y,z)
  df
      w   x   y   z
  1   A   1   3   0.93767621
  2   B   1   4   0.09169992
  3   C   1   5   0.49012926
  4   D   1   6   0.90886690
  5   E   1   8   0.37058120
  6   F   1   10  0.83558267
  7   A   2   3   0.42670001
  8   B   2   4   0.05656252
  9   C   2   5   0.70694423
  10  D   2   7   0.13634309
  11  E   2   9   0.92065671
  12  F   2   10  0.56276176
  </code></pre>
  
  <p>What I want is to obtain the ratios of z from the two levels of x and taking into account the variables w and y. So the level "A" from the variable "w" in the level "3" from the variable "y" should be:</p>
  
  <pre><code>df$z[1]/df$z[7]
  </code></pre>
  
  <p>With aggregate function should be something like this:</p>
  
  <pre><code>final&lt;-aggregate(z~y:w, data=df)
  </code></pre>
  
  <p>However, I know that I miss something because in the variable y there are some classes that not appear in the two categories of w (e.g. 7, 8 and 9). </p>
  
  <p>Any help will be welcomed!</p>