title: Create a new data frame based on another dataframe
body: <p>I am trying to use a huge dataframe (180000 x 400) to calculate another one that would be much smaller.</p>
  
  <p>I have the following dataframe</p>
  
  <pre><code>df1=data.frame(LOCAT=c(1,2,3,4,5,6),START=c(120,345,765,1045,1347,1879),END=c(150,390,802,1120,1436,1935),CODE1=c(1,1,0,1,0,0),CODE2=c(1,0,0,0,-1,-1))
  
  df1
    LOCAT START  END CODE1 CODE2
  1     1   120  150     1     1
  2     2   345  390     1     0
  3     3   765  802     0     0
  4     4  1045 1120     1     0
  5     5  1347 1436     0    -1
  6     6  1879 1935     0    -1
  </code></pre>
  
  <p>This is a sample dataframe. The rows continue until 180000 and the columns are over 400.
  What I need to do is create a new dataframe based on each column that tells me the size of each continues "1" or "-1" and returns it with the location, size and value.</p>
  
  <p>Something like this for CODE1:</p>
  
  <pre><code>   LOCAT SIZE VALUE
  1 1 to 2  270   POS
  2 4 to 4   75   POS
  </code></pre>
  
  <p>And like this for CODE2:</p>
  
  <pre><code>   LOCAT SIZE VALUE
  1 1 to 1   30   POS
  2 5 to 6  588   NEG
  </code></pre>
  
  <p>Unfortunately I still didn't figure out how to do this. I have been trying several lines of code to develop a function to do this automatically but start to get lost or stuck in loops and it seems that nothing works.</p>
  
  <p>Any help would be appreciated.
  Thanks in advance</p>