[R] Problem with read.table()
Kristian Skrede Gleditsch
kgleditsch at ucsd.edu
Thu Jul 21 16:18:27 CEST 2005
Thanks to all who responded to my earlier message. The problem lies in
that apostrophes (i.e., ') in some of the text fields are read as quotes.
The file can be read without problems setting quotes="" in read.table.
Incidently, read.delim() also works, even without setting quotes=""
explicitly.
best regards,
Kristian Skrede Gleditsch
Department of Political Science, UCSD
(On leave, University of Essex, 2005-6)
Tel: +44 1206 872499, Fax: +44 1206 873234
Email: kgleditsch at ucsd.edu or ksg at essex.ac.uk
http://weber.ucsd.edu/~kgledits/
Kristian Skrede Gleditsch wrote:
> Dear all,
>
> I have encountered a strange problem with read.table(). When I try to
> read a tab delimited file I get an error message for line 260 not being
> equal to 14 (see below).
>
> Using count.fields() suggests that a number of lines have length not
> equal to 14, but not 260.
>
> Looking at the actual file, however, I cannot see anything wrong with
> any lines. They all seem to have length 14, there are no double tabs
> etc., and the file reads correctly in other programs. Does anyone have
> any suggestions as to what this might stem from?
>
> I have placed a copy of the file at
> http://dss.ucsd.edu/~kgledits/archigos_v.1.9.asc
>
> regards,
> Kristian Skrede Gleditsch
>
>
> > archigos1.9 <- read.table("c:/work/work12/archigos/archigos_v.1.9.asc",
> + sep="\t",header=T,as.is=T,row.names=NULL)
> Error in scan(file = file, what = what, sep = sep, quote = quote, dec =
> dec, :
> line 260 did not have 14 elements
> > a <- count.fields("c:/work/work12/archigos/archigos_v.1.9.asc",sep="\t")
> > a <- data.frame(c(1:length(a)),a)
> > a[a[,2]!=14,]
> c.1.length.a.. a
> 150 150 10
> 313 313 10
> 424 424 10
> 1189 1189 5
> 1510 1510 10
> 1514 1514 10
> 1590 1590 5
> 1600 1600 10
> 1612 1612 10
> 1618 1618 10
> 1619 1619 10
> 1709 1709 10
> 1722 1722 10
> 1981 1981 10
> 1985 1985 10
> 2112 2112 10
> 2178 2178 10
> 2208 2208 10
> 2224 2224 10
> 2530 2530 5
> 2536 2536 5
> 2573 2573 5
> 2928 2928 5
More information about the R-help
mailing list