title: Sampling and Calculation in R
body: <p>I have a file that contains two columns (Time , VA). The file is large and I managed to read it in R(used read and subset -not a practical for large file). Now, I want to do sampling based on the time, where each sample has a sample size and sample shift. Sample size is fixed value for the whole process of sampling e.g. sampleSize=10 second. Sample shift is the start point for each new sample (after First sample). For example, if sampleShift =4 sec and the sampleSize is 10 sec , that means the second sample will start from 5 sec and add 10 sec as the sample sample size=10 sec. For each sample I want feed the 
  -VA- values to a function to some calculation.</p>
  
  <pre><code>Sampling &lt;- function(values){
  # Perform the sampling 
  lastRowNumber&lt;- #specify the last row manually
  sampleSize&lt;-10
  lastValueInFile&lt;-lastRowNumber-sampleSize
  
  for (i in 1: (lastValueInFile ) ){ 
    EndOfShift&lt;-9+i
    sample&lt;-c(1:sampleSize)
    h&lt;-1
  
    for(j in i:EndOfShift){        
      sample[h] &lt;- values[j,1]
      h&lt;-h+1
    }
    print(sample)
    #Perform the Calculation on the extracted sample
    #--Samp_Calculation&lt;-SomFunctionDoCalculation(sample) 
  }
  }
  </code></pre>
  
  <p>The problems with my try are:
  1) I have to specify the lastRow number manually for each file I read.
  2) I was trying to do the sampling based on rows number not the Time value. Also, the shift was by one for each sample.</p>
  
  <p>file sample:</p>
  
  <pre><code>Time     VA
  0.00000 1.000
  0.12026 2.000
  0.13026 2.000
  0.14026 2.000
  0.14371 3.000
  0.14538 4.000
   ..........
   ..........
  15.51805 79.002
  15.51971 79.015
  15.52138 79.028
  15.52304 79.040
  15.52470 79.053
  .............
  </code></pre>
  
  <p>Any suggestion for more professional way ?    </p>