[R] More Columns than column names Error

arun smartpink111 at yahoo.com
Tue Oct 22 15:41:21 CEST 2013

 lines1 <- readLines("Garbage.txt",warn=FALSE)
dat1 <- read.table(text=gsub("\t+","\t",lines1),stringsAsFactors=FALSE,sep="\t",check.names=FALSE,header=TRUE)
#'data.frame':    10 obs. of  3 variables:
# $ Material            : chr  "Food Scraps" "Glass" "Metals" "Paper" ...
# $ Weight(Million Tons): num  25.9 12.8 18 86.7 24.7 ...
# $ Percent             : num  11.2 5.5 7.8 37.4 10.7 6.8 5.5 11.9 3.2 100
 barplot(dat1[-10,2],names.arg=dat1[-10,1],ylab=colnames(dat1)[2],col=rainbow(9),main="American garbage")


Hello guys, I'm having this weird problem with my assignment. I can't seem to import the data that I have created. 

I keep getting an error that says "Error: More Columns than Column names" 

This is my data file. 

Was also wondering if you guys could send me into the right direction on how to do this. 

1. Create a data frame with the data given above. 
2. Create the bar plot for weight variable with appropriate labels. Resize the graphics 
panel/ window so that all labels are visible. 
3. Add colors. Suppose n is the number of bars. 
> barplot(..., col = rainbow(n)) 
4. Save the plot to garbageweight.jpg 

This is how it's supposed to look like at the end.

More information about the R-help mailing list