title: R Error: Data and vector are not the same length
body: <p>I'm trying to plot bacterial growth rates in R  using a premade script. Basically I am attempting to use a function to give me the steepest slope between a set of points. I'm using the following data frame "tmp":</p>
  
  <pre><code>&gt; str(tmp)
  'data.frame':   54 obs. of  10 variables:
   $ Strain     : Factor w/ 54 levels "11A023","11A045",..: 1 2 3 4 5 6 7 8 9 10 ...
   $ 0          : num  0.048 0.05 0.047 0.053 0.051 0.051 0.041 0.05 0.049 0.045 ...
   $ 21.5       : num  0.04 0.042 0.037 0.037 0.041 0.03 0.031 0.043 0.037 0.036 ...
   $ 47.5       : num  0.027 0.041 0.032 0.035 0.034 0.026 0.02 0.042 0.034 0.03 ...
   $ 71.5       : num  0.026 0.039 0.028 0.032 0.032 0.022 0.019 0.041 0.03 0.031 ...
   $ 94.5       : num  0.025 0.037 0.027 0.026 0.03 0.017 0.015 0.037 0.028 0.024 ...
   $ 117.8333333: num  0.023 0.031 0.026 0.035 0.029 0.017 0.017 0.034 0.027 0.022 ...
   $ 144.5      : num  0.021 0.032 0.031 0.029 0.035 0.022 0.012 0.034 0.03 0.023 ...
   $ 154.75     : num  0.022 0.032 0.031 0.033 0.042 0.026 0.016 0.041 0.036 0.025 ...
   $ 194        : num  0.02 0.034 0.034 0.03 0.04 0.022 0.014 0.038 0.034 0.028 ...
  </code></pre>
  
  <p>And the following code:</p>
  
  <pre><code>tmp = read.csv("sorted_data.csv") #substitute your file name for 'sorted_data'
  source("find_gr.R") #this command loads the script (find_gr) that contains the analysis functions (needs to be in the present working directory)
  time &lt;- seq(0,9.25) #edit as appropriate
                                  #note that the growth rate output will be scaled by the time units you use here (per hour, per min, per century, etc.)
  
  M = nrow(tmp)
  N = ncol(tmp)
  
  pdf("growth_rate_plots.pdf", paper="letter", width=7.5, height=10) #substitute your desired file name for 'growth_rate_plots'
  growth.rates = NULL
  
  for (i in 1:M) {
    print(i)
    gr &lt;- findgr(tmp[i, 3:N], time, tmp[i, 2], int=12, r2=0.6) #3 in [i, 3:N] is the column number where the data starts;  
    #2 in [i, 2] is the column containg the label you want on the plot; 
    #int is number of points taken at one time as an interval to find the highest slope; 
    #vary (i.e. lower) r2, i.e. rsquared as needed, blanks can be a problem here
    growth.rates &lt;- rbind(growth.rates, gr)
  }
  dev.off()
  </code></pre>
  
  <p>When I run the code, I get the following error:</p>
  
  <pre><code>Error: Your data and time are not the same length.
  Error in findgr(tmp[i, 3:N], time, tmp[i, 2], int = 12, r2 = 0.6) :  
  </code></pre>
  
  <p>I believe this refers to the vector 'time' created. My dataframe is length 9 or 10 (not sure if I count $Strain in length). I have tried creating a time vector with varying lengths, but always get this error returned.</p>
  
  <p>Is there anything I am doing wrong? What should I be looking for? </p>
  
  <p>Much thanks for any help, I am a complete beginner at this.</p>
  
  <p>**Scripts were obtained from <a href="https://www.princeton.edu/genomics/botstein/protocols/" rel="nofollow">https://www.princeton.edu/genomics/botstein/protocols/</a></p>