Re: [R] How to read an excel data into R?

From: Spencer Graves <>
Date: Thu 23 Jun 2005 - 10:14:34 EST

          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")

	  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
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!

Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA <>
Tel:  408-938-4420
Fax: 408-280-7915

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Thu Jun 23 10:18:25 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:57 EST