title: How to do a row based process using Deedle (Frame in and Frame out)
body: <p>I am trying to use Deedle to do row based process on a DataFrame. But i just can't get my mind tuned into the Deedle way.</p>
  
  <p>Say for a Frame like </p>
  
  <pre><code>    Indicator1 Indicator2
  1   100        200
  2   300        500
  3   -200       1000
  </code></pre>
  
  <p>Say there are some rules needs to be applied to each indicator:</p>
  
  <ol>
  <li>if Indicator value is less than 500 and larger than 0, multiply it by 1.1</li>
  <li>if Indicator value is less than 0, make it NaN</li>
  </ol>
  
  <p>I have been trying to use <code>Frame.mapRow</code> .... functions. </p>
  
  <p>I know I can use the </p>
  
  <pre><code>fun v -&gt; let indVal = v.GetAs&lt;Int&gt;("Indicator1");
           let newIndVal = match indVal with 
                           |...... logic  
                           |...... some other logic
           let indVal2 = v.GetAs&lt;Int&gt;("Indicator2");
           let newIndVal2 = match indVal2 with 
                           |...... logic  
                           |...... some other logic  
  </code></pre>
  
  <p>with the <code>Frame.mapRow</code> ....   </p>
  
  <p>But I am stuck at how to make the <code>newIndVal</code> and <code>newIndVal2</code> back into the a row and eventually back into a new data frame.</p>
  
  <p>What I am trying to achieve is a frame in and frame out. Also I only know to process the column one by one (after retrieving them by index or name). If the logic to be applied are generic, is there a way NOT to apply the logic one column by one column?</p>
  
  <p>A imperative (and really simple) way to do this with C or C# 2d array is </p>
  
  <pre><code>loop through the row dimension
      loop through the column dimension
           apply the rule as the side effect to the array[row,col]
  </code></pre>
  
  <p>How to achieve this in Deedle? </p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Leaf Garland's suggestion works great if the calculation doesn't need to reference other columns from the same row. For my case, I need to look at the data row by row, hence I would like to use Frame.mapRows. I should have been clear on the simplified requirements:</p>
  
  <p>Say for a Frame like </p>
  
  <pre><code>    Indicator1 Indicator2
  1   100        200
  2   &lt;Missing&gt;  500
  3   -200       1000
  4   100        &lt;Missing&gt;
  5   &lt;Missing&gt;  500
  6   -200       100
  </code></pre>
  
  <p>For example
  if indicator1 is less than 300, new Indicator2 value is Indicator2 +  5% * Indicator1</p>
  
  <p>I need to use </p>
  
  <pre><code>mapRows fun k v -&gt; let var1 = v.get("Indicator1")
                     let var2 = v.get("Indicator2")
                     run through the conditions and produce new var1 and var2
                     produce a objectSeries
  |&gt; Frame.ofRows
  </code></pre>
  
  <p>The pesudo code above sounds simple but i just can figure out how to reproduce a proper objectSeries to recreate the Frame.</p>
  
  <p>I also noticed something i can't explain with mapRows function [SO question]: <a href="https://stackoverflow.com/questions/26049661/deedle-frame-maprows-how-to-properly-use-it-and-how-to-construct-objectseries-pr">Deedle Frame.mapRows how to properly use it and how to construct objectseries properly</a></p>
  
  <p><strong>Update</strong></p>
  
  <p>Since the original question was posted, I have since used Deedle in C#. To my surprise the row based calculation is very easy in C# and the way C# Frame.rows function handle missing values are very different than F# mapRows function. The following is a very basic example i used to try and true the logic. it might be useful to anyone who is searching for similar application:</p>
  
  <p>Things to pay attention to are:
  1. The rows function didn't remove the row while both columns' value are missing
  2. The mean function is smart enough to calculate mean based on available data point.</p>
  
  <pre><code>using System.Text;
  using System.Threading.Tasks;
  using Deedle;
  
  namespace TestDeedleRowProcessWithMissingValues
  {
      class Program
      {
          static void Main(string[] args)
          {
              var s1 = new SeriesBuilder&lt;DateTime, double&gt;(){
                   {DateTime.Today.Date.AddDays(-5),10.0},
                   {DateTime.Today.Date.AddDays(-4),9.0},
                   {DateTime.Today.Date.AddDays(-3),8.0},
                   {DateTime.Today.Date.AddDays(-2),double.NaN},
                   {DateTime.Today.Date.AddDays(-1),6.0},
                   {DateTime.Today.Date.AddDays(-0),5.0}
               }.Series;
  
              var s2 = new SeriesBuilder&lt;DateTime, double&gt;(){
                   {DateTime.Today.Date.AddDays(-5),10.0},
                   {DateTime.Today.Date.AddDays(-4),double.NaN},
                   {DateTime.Today.Date.AddDays(-3),8.0},
                   {DateTime.Today.Date.AddDays(-2),double.NaN},
                   {DateTime.Today.Date.AddDays(-1),6.0}                 
               }.Series;
  
              var f = Frame.FromColumns(new KeyValuePair&lt;string, Series&lt;DateTime, double&gt;&gt;[] { 
                  KeyValue.Create("s1",s1),
                  KeyValue.Create("s2",s2)
              });
  
              s1.Print();
              f.Print();
  
  
              f.Rows.Select(kvp =&gt; kvp.Value).Print();
  
  //            29/05/2015 12:00:00 AM -&gt; series [ s1 =&gt; 10; s2 =&gt; 10]
  //            30/05/2015 12:00:00 AM -&gt; series [ s1 =&gt; 9; s2 =&gt; &lt;missing&gt;]
  //            31/05/2015 12:00:00 AM -&gt; series [ s1 =&gt; 8; s2 =&gt; 8]
  //            1/06/2015 12:00:00 AM  -&gt; series [ s1 =&gt; &lt;missing&gt;; s2 =&gt; &lt;missing&gt;]
  //            2/06/2015 12:00:00 AM  -&gt; series [ s1 =&gt; 6; s2 =&gt; 6]
  //            3/06/2015 12:00:00 AM  -&gt; series [ s1 =&gt; 5; s2 =&gt; &lt;missing&gt;]
  
  
              f.Rows.Select(kvp =&gt; kvp.Value.As&lt;double&gt;().Mean()).Print();
  
  //            29/05/2015 12:00:00 AM -&gt; 10
  //            30/05/2015 12:00:00 AM -&gt; 9
  //            31/05/2015 12:00:00 AM -&gt; 8
  //            1/06/2015 12:00:00 AM  -&gt; &lt;missing&gt;
  //            2/06/2015 12:00:00 AM  -&gt; 6
  //            3/06/2015 12:00:00 AM  -&gt; 5
  
  
              //Console.ReadLine();
          }
      }
  }
  </code></pre>