title: R nested for loop structure for all combinations of two variables
body: <p>I want to run a function on each level of a data.frame variable based on the condition of each level of another data.frame variable (or lists, if it's better to work with them for some reason).  </p>
  
  <p>If one of the variables achieves a certain condition (e.g., > 15), I then want to run a simple function (e.g., product) on each pair of variables and add the results to a new list. For the sake of my needs and other's future needs, I am hoping for a 
  solution that is flexible for any condition and any function.</p>
  
  <p>I am new to programming/R and do not know how to appropriate structure a for loop (or other method) in order to run the function for all combinations of elements in both data.frame variables. It seems like this should be really easy to achieve but I've been searching for hours and cannot find a solution. </p>
  
  <p>This is the nested for loop code I am working on:</p>
  
  <pre><code>df1 &lt;- data.frame(c(1, 2, 3))
  df2 &lt;- data.frame(c(10, 20, 30))
  
  list1 &lt;- list()
  for (i in 1:length(df1)) {
    for (j in 1:length(df2)) {
      if (df2[j,] &gt; 15) {
        list1[[i]] &lt;-  df1[i,] * df2[j,]}
      }}
  list1
  </code></pre>
  
  <p>When I run the current code I get and empty list results: list().
  What I want returned is something like this:</p>
  
  <pre><code>[[1]]
  [1] 20
  
  [[2]]
  [1] 30
  
  [[3]]
  [1] 40
  
  [[4]]
  [1] 60
  
  [[5]]
  [1] 60
  
  [[6]]
  [1] 90
  </code></pre>