[R] Importing Large Dataset into Excel
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Dec 12 09:47:46 CET 2007
I would say that the issue is more often the character ', which is allowed
as a quote in read.table and not in read.csv.
As for
>>> Also, is there an easier way to import data from R into Excel
>>> using a single line of R code?
I think it means import from Excel into R, and there are several simpler
ways described in the 'R Data Import/Export manual'.
On Wed, 12 Dec 2007, Philippe Grosjean wrote:
> The problem is often a misspecification of the comment.char argument.
> For read.table(), it defaults to '#'. This means that everywhere you
> have a '#' char in your Excel sheet, the rest of the line is ignored.
> This results in a different number of items per line.
>
> You should better use read.csv() which provides better default arguments
> for your particular problem.
> Best,
>
> Philippe Grosjean
>
>
> jim holtman wrote:
>> ?count.fields
>>
>> count.fields will tell you how many items are in each line. As you
>> said, they should all be the same, but this will confirm it.
>>
>> field.count <- count.fields("newborn edit.csv", sep=",")
>> table(field.count) # determine count of the fields on a line
>>
>> On Dec 11, 2007 7:15 PM, Wayne Aldo Gavioli <wgavioli at fas.harvard.edu> wrote:
>>> Hello all,
>>>
>>>
>>> I seem to be having a problem importing a data set from Excel into R. I'm using
>>> the "read.table" command to import the data with the following line of code:
>>>
>>>> newborn<-read.table("newborn edit.csv", header=T, sep=",")
>>>
>>> where "newborn edit.csv" is the name of the file. Unfortunately, I'm getting
>>> back the following error message:
>>>
>>>
>>> "Error in scan(file,, what, nmax, sep, dc, quote, skip, nlines, na.string, :
>>> line 528 did not have 44 elements"
>>>
>>>
>>> As far as I can tell, line 528 of the spreadsheet table does have the same
>>> number of elements as the other rows - by chance can this error message mean
>>> anything else? Also, is there an easier way to import data from R into Excel
>>> using a single line of R code?
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list