title: R: Error in eval(predvars, data, env) : object 'x' not found
body: <p>I am quite new to R, so this might seem like a really simple question. However I don't know specifically what to search for because I don't really know what is causing the problem. Both CSV-files mentioned below are formatted in the same way, which is the reason I don't know what is causing the trouble. However the CSV that is returning the error mentioned below has many more rows than the other.</p>
  
  <p>I have a certain dataset I want to run a linear model on (lm in R). I imported it into R from a CSV using this code in R:</p>
  
  <blockquote>
    <p>rawData=read.csv("dataset.csv", header=T)</p>
  </blockquote>
  
  <p>When requesting an output of the ten top rows by we get:</p>
  
  <pre><code>&gt; head(rawData, 10)
     ï..x   y
  1     1 0.0
  2     2 0.0
  3     3 0.0
  4     4 0.0
  5     5 0.0
  6     6 0.5
  7     7 0.0
  8     8 0.0
  9     9 0.1
  10   10 0.0
  </code></pre>
  
  <p>From the above output we see that the top row display as follows:</p>
  
  <pre><code>ï..x   y
  </code></pre>
  
  <p>Running a linear model on the last one returns an error messages:</p>
  
  <pre><code>simple.fit = lm(x~y, data=dataset)
  summary(simple.fit)
  </code></pre>
  
  <p>The error message returned is:</p>
  
  <pre><code>Error in eval(predvars, data, env) : object 'x' not found
  </code></pre>
  
  <p>How can this be solved?</p>
  
  <p>As we can see below the output from an import of another CSV file (I just used  for testing linear regression) in R the output is as follows:</p>
  
  <pre><code>&gt; rawData=read.csv("testing.csv", header=T)
  &gt; head(rawData, 10)
               x          y
  1  82.58321982 134.907414
  2  73.92246618 134.085180
  3  34.88744536         NA
  4  61.83998269 114.530638
  5  16.77594025  31.376437
  6   0.01673734   8.764634
  7  44.45764646  73.285341
  8  10.34490930  18.859865
  9  42.76713229  72.946609
  10 20.85663802  28.637286
  </code></pre>
  
  <p>Here we see the top row have simply:</p>
  
  <pre><code>x          y
  </code></pre>
  
  <p>Running a linear model on the last one returns no error messages and gives an output
      simple.fit = lm(x~y, data=testing)
      summary(simple.fit)</p>