title: How to loop through a list in R
body: <p>I have a list lets say:</p>
  
  <pre><code>dataSet$mixed_bag &lt;- list("Hello", c("USA", "Red", "100"), c("India", "Blue", "76"))
  </code></pre>
  
  <p>I want to iterate through this list and create new variables based on the contents of the list. 
  A pseudo code would look something like this.</p>
  
  <pre><code>foreach row in dataSet$mixed_bag {
      if (sapply(dataSet$mixed_bag, length) == 3) {
          dataSet$country &lt;- dataSet$mixed_bag[[row]][1];
          dataSet$color &lt;- dataSet$mixed_bag[[row]][2];
          dataSet$score &lt;- dataSet$mixed_bag[[row]][3];
      } else if (sapply(dataSet$mixed_bag, length) == 2) {
         #Do something else
      } else {
         # Do nothing
      }
  }
  </code></pre>
  
  <p>Please suggest how would I do this in R</p>