title: Error with read.table
body: <p>I am struggling with a confusing error in R. I have dataset including many columns. When I read it, I see error message such as "Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,". </p>
  
  <pre><code>    &gt; data=read.table(file("D:/R/data.txt"), header=T)
      Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
      line 1 did not have 26 elements
  </code></pre>
  
  <p>Thus, I tried the below,</p>
  
  <pre><code>    &gt; data=read.table(file("D:/R/data.txt"), fill=T, header=F)
      &gt; head(data)
        V1      V2      V3      V4      V5        V6        V7         V8
      1 Year      Na     NH4       K      Mg        Ca        Cl        NO3
      2 2009 40.9311  89.072 65.4617 48.5279 3091.9586 52.782114 173.414523
      3 2009 19.8996 75.3554  22.219 11.8805  223.5573  28.51786 219.186039
  </code></pre>
  
  <p>OK, anyway, R read my data. Then I want plot, so I remove 1st row, which is my header actually.</p>
  
  <pre><code>    &gt; data&lt;-data[-c(1), ]
      &gt; head(data)
        V1      V2      V3      V4      V5        V6        V7         V8
     2 2009 40.9311  89.072 65.4617 48.5279 3091.9586 52.782114 173.414523
  
     &gt; boxplot(V20~factor(V1), data=data, main="")
       Error in boxplot.default(split(mf[[response]], mf[-response]), ...) : 
       adding class "factor" to an invalid object
     &gt; a&lt;-aggregate(V20~V1, data=data, mean) 
      There were 50 or more warnings (use warnings() to see the first 50)
  </code></pre>
  
  <p>Initially, I just wanted to read my data set and aggregate each column as a function of year (first colulmn). But I see the error message, which might ask me to make my data into data frame. Then I am lost how to handle it. Is there any way to read my data with header and simply plot a box plot and aggregate data?</p>