title: data$column returning null in a user-defined function
body: <p>I'm new at  R (and stackoverflow , too), so please forgive any possible stupidity!</p>
  
  <p>I wrote a function </p>
  
  <pre><code>     getvariance &lt;-function(data, column)
  </code></pre>
  
  <p>that returns the variance of values in <code>column</code> in <code>data</code></p>
  
  <p>In the function I wrote</p>
  
  <pre><code>    mydata = read.csv(data)
      for i=1:datasize {
        x=(mydata$column)[i]
        //compute variance of x
      }
  </code></pre>
  
  <p>When I call </p>
  
  <pre><code>     getvariance("randomnumbers.csv", X1)
  </code></pre>
  
  <p>x is returned as a column of null values.</p>
  
  <p>However, when I simply write</p>
  
  <pre><code>     x=(mydata$X1[i])
  </code></pre>
  
  <p>it prints the full column with numerical values.</p>
  
  <p>Can anyone help me understand why <code>mydata$column[i]</code> doesn't work when column's a parameter of a function?</p>
  
  <p>Thanks in advance.</p>