title: R-Programming: Error in seq.default(1, data_length) : 'to' must be of length 1
body: <p>Hi I am trying to calculate group standardized values of the data variables using the following function.</p>
  
  <pre><code>groupStandardise &lt;- function(variables, groupvariable)
  {
   # find out how many variables we have
   variables &lt;- as.data.frame(variables)
   numvariables &lt;- length(variables)
   # find the variable names
   variablenames &lt;- colnames(variables)
   # calculate the group-standardised version of each variable
   for (i in 1:numvariables)
   {
      variablei &lt;- variables[[i]]
      variablei_name &lt;- variablenames[[i]]
      variablei_Vw &lt;- calcWithinGroupsVariance(variablei, groupvariable)
      variablei_mean &lt;- mean(variablei)
      variablei_new &lt;- (variablei - variablei_mean)/(sqrt(variablei_Vw))
      data_length &lt;- nrow(variablei)
      if (i == 1) { variables_new&lt;-data.frame(row.names=seq(1,data_length))}
      variables_new[`variablei_name`] &lt;- variablei_new
   }
   return(variables_new)
   }
  </code></pre>
  
  <p>While calling the function as </p>
  
  <pre><code>groupstandardisedconcentrations &lt;- groupStandardise(data[,2:14], data[,1])
  </code></pre>
  
  <p>I am getting this error</p>
  
  <blockquote>
    <p>Error in seq.default(1,data_length) : 'to' must be of length 1</p>
  </blockquote>
  
  <p>output of str(data) is below (v1 is the group variable):</p>
  
  <pre><code>'data.frame':   45 obs. of  11 variables:
   $ V1 : int  2 3 3 2 3 2 2 2 3 2 ...
   $ V2 : num  1.3243 -2.4546 0.1352 0.0676 -1.1901 ...
   $ V3 : num  0.913 -2.644 0.663 1.217 -0.409 ...
   $ V4 : num  -1.863 1.965 -0.698 -0.945 0.617 ...
   $ V5 : num  -0.574 1.031 -0.308 -0.574 0.354 ...
   $ V6 : num  -0.8963 2.5702 0.0736 -1.3671 0.9045 ...
  </code></pre>
  
  <p>Any suggestion to resolve this?</p>