Your error message tells me that you have different numbers of fields in different lines. You say you, "copied and pasted the excel data into a txt file". I usually copy what I want into a clean sheet then File -> Save, then File -> "Save As" -> "Save as type" = "CSV (Comma delimited) (*.csv)" or "Text (Tab delimited) (*.txt)". Excel will ask if I'm sure a couple of times, and I say yes. If that's what you've done and still have a problem, then I have other tools:
First, I'll assign the file name to something like "File". Then, 'readLines(File, n=9)' tells me if the file starts as I think it does. If I've got extra headers, it will tell me that. Then, I do something like the following: n.flds <- count.fields(File, sep="\t") plot(n.flds) sd(n.flds) Then I play with the arguments to "count.fields" until 'sd(n.flds)' is 0. Then I use "read.table" with arguments as I used to get everything right in 'count.fields'. If I can't get sd(n.flds) to 0, you can try read.table with 'fill=TRUE'. However, when you do that, you need to check to make sure all the columns line up correctly with the shorter lines. Also, this issue has been discussed many times. 'RSiteSearch("read excel")' just produced 1196 hits for me. If the above doesn't work, you might try skimming a few from that list. hope this helps. spencer graves Ling Jin wrote: > Hi all, > > Does anybody know the easiest way to import excel data into R? I copied > and pasted the excel data into a txt file, and tried read.table, but R > reported that > > Error in read.table("data_support.txt", sep = " ", header = T) : > more columns than column names > > Thanks! > > Ling > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA [EMAIL PROTECTED] www.pdf.com <http://www.pdf.com> Tel: 408-938-4420 Fax: 408-280-7915 ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html