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? Thanks, Wayne
Sorry, the title of this should read "From Excel into R". Quoting Wayne Aldo Gavioli <wgavioli at fas.harvard.edu>:> > 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? > > > Thanks, > > > Wayne > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
?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? > > > Thanks, > > > Wayne > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Did you try read.xls() in the xlsReadWrite library, I have had good success with this. Corey Corey S. Sparks, Ph.D. Assistant Professor Department of Demography and Organization Studies University of Texas San Antonio One UTSA Circle San Antonio, TX 78249 email:corey.sparks@utsa.edu [[alternative HTML version deleted]]
Hi Wayne, I'm assuming that you file is really a comma-separated file (*.csv) and not an Excel workbook (*.xls) saved with a .csv extension, right? That (in my experience) is a common mistake. You should open your file with a simple text editor (notepad will do if the file is not too large) and review line 528, instead of reviewing the spreadsheet in Excel. You should be able to spot the problem right away. Julian Wayne Aldo Gavioli 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? > > > Thanks, > > > Wayne > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.