Hi ! I am new to R, and using the MAC version onto Mac OS 9.1. My question concerns the problem I encounter when I try to read some data I have using the read.table function. I always get an error of type : Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 1 did not have 9 elements Here is my code: varnames <- c("names", "symbol", "price", "displ", "gas", "weight", "reliab", "origin", "type") cardat <- read.table("PowerMac 7300:Logiciels de Statistiques:rm162:car02.txt", col.names=varnames, as.is=c(F,T,F,F,F,F,F,F,F,F)) Can you advice me ? Thanks in advance, Pascale Tremblay
Perhaps your data entrys delimited with comma, semicolon so you have to use sep="," or sep=";" . For tab-delimited data i take read.delim. hope this helps.christian ----- Original Message ----- From: "ptremb17" <ptremb17 at po-box.mcgill.ca> To: "R-HELP" <r-help at stat.math.ethz.ch> Sent: Saturday, February 01, 2003 3:24 AM Subject: [R] Read.table problem> Hi ! > > I am new to R, and using the MAC version onto Mac OS 9.1. My questionconcerns> the problem I encounter when I try to read some data I have using the > read.table function. I always get an error of type : Error in scan(file > file, what = what, sep = sep, quote = quote, dec = dec, : > line 1 did not have 9 elements > > Here is my code: > > varnames <- c("names", "symbol", "price", "displ", "gas", "weight","reliab",> "origin", "type") > > cardat <- read.table("PowerMac 7300:Logiciels de > Statistiques:rm162:car02.txt", col.names=varnames, > as.is=c(F,T,F,F,F,F,F,F,F,F)) > > Can you advice me ? > > Thanks in advance, > > Pascale Tremblay > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Dear Pascale, It seems an obvious question, so perhaps not worth asking, but did you check that line 1 of the data file actually has 9 elements (separated by white space)? (I notice that your as.is argument specifies 10 elements; I don't believe that this should cause a problem if there are really 9.) If inspection of the file doesn't reveal the problem, you could try to run count.fields() on the file to see how many elements R thinks are in each line. John At 09:24 PM 1/31/2003 -0500, ptremb17 wrote:>Hi ! > >I am new to R, and using the MAC version onto Mac OS 9.1. My question >concerns >the problem I encounter when I try to read some data I have using the >read.table function. I always get an error of type : Error in scan(file >file, what = what, sep = sep, quote = quote, dec = dec, : > line 1 did not have 9 elements > >Here is my code: > >varnames <- c("names", "symbol", "price", "displ", "gas", "weight", "reliab", >"origin", "type") > >cardat <- read.table("PowerMac 7300:Logiciels de >Statistiques:rm162:car02.txt", col.names=varnames, >as.is=c(F,T,F,F,F,F,F,F,F,F))----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox -----------------------------------------------------
----- Original Message ----- From: "ptremb17" <ptremb17 at po-box.mcgill.ca> length(varnames) = 9 length(c(F,T,F,F,F,F,F,F,F,F))) = 10 To: "R-HELP" <r-help at stat.math.ethz.ch> Sent: Saturday, February 01, 2003 3:24 AM Subject: [R] Read.table problem> Hi ! > > I am new to R, and using the MAC version onto Mac OS 9.1. My questionconcerns> the problem I encounter when I try to read some data I have using the > read.table function. I always get an error of type : Error in scan(file > file, what = what, sep = sep, quote = quote, dec = dec, : > line 1 did not have 9 elements > > Here is my code: > > varnames <- c("names", "symbol", "price", "displ", "gas", "weight","reliab",> "origin", "type") > > cardat <- read.table("PowerMac 7300:Logiciels de > Statistiques:rm162:car02.txt", col.names=varnames, > as.is=c(F,T,F,F,F,F,F,F,F,F)) > > Can you advice me ? > > Thanks in advance, > > Pascale Tremblay > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help