[R] write.table error
Ross Darnell
r.darnell at shrs.uq.edu.au
Mon Jul 8 03:52:38 CEST 2002
OK . Point taken. Here is the original set of commands
> > > write.table(all,file="agree.csv",row.names=F)
> > Error in "rownames<-"(*tmp*, value = row.names(x)) :
> > length of dimnames[1] not equal to array extent
> > > is.data.frame(all)
> > [1] TRUE
> > > dim(all)
> > [1] 854 18
> > > length(row.names(all))
> > [1] 854
Drop the row.names argument then the traceback
> write.table(all,"agree.csv",sep=",")
Error in "rownames<-"(*tmp*, value = row.names(x)) :
length of dimnames[1] not equal to array extent
> traceback()
4: "rownames<-"(*tmp*, value = row.names(x))
3: is.na.data.frame(x)
2: is.na(x)
1: write.table(all, "agree.csv", sep = ",")
>
Then trying the is.nadata.frame function
> write.ex <- is.na.data.frame(all)
Error in "rownames<-"(*tmp*, value = row.names(x)) :
length of dimnames[1] not equal to array extent
> traceback()
2: "rownames<-"(*tmp*, value = row.names(x))
1: is.na.data.frame(all)
Repeat what is.na.data.frame does
> y <- do.call("cbind",lapply(all,"is.na"))
> rownames(y) <- row.names(all)
Error in "rownames<-"(*tmp*, value = row.names(all)) :
length of dimnames[1] not equal to array extent
Let's have a look at "y"
> str(y)
logi [1:1708, 1:18] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:18] "time" "obs" "state1" "state2" ...
>
There is twice as many rows in "y" as there should be. Compare first
854 with second.
> sum(y[1:854,]!=y[1:854,])
[1] 0
Why does this happen with this particular data frame! Try each variable
> names(all)
[1] "time" "obs" "state1" "state2" "name" "agree"
[7] "symmetric" "Name" "AWIA1" "AWIA2" "AS1" "AS2"
[13] "AWAA1" "AWAA2" "DA1" "DA2" "DR1" "DR2"
> ...
> length(all$symmetric)
[1] 1708
This is twice as long as other variables. Why did I think this was
impossible? Can variables in data.frames by of different length?
> yy <- data.frame(v1=1:10,v2=1:15)
Error in data.frame(v1 = 1:10, v2 = 1:15) :
arguments imply differing number of rows: 10, 15
>
Slightly confused
Thanks for the help
Ross Darnell
<ripley at stats.ox.ac.uk> writes:
> You gien us nothing to reproduce this with, and other examples work.
> R does have debugging tools that would allow you to investigate this.
> In particular, as rownames<- is not actually used in write.table,
> the result of traceback() is the minimum that is needed when reporting an
> error.
>
> Just one possbility: it should be `row.names=FALSE', and if you had a
> variable called F this might be the explanation.
>
> On 5 Jul 2002, Ross Darnell wrote:
>
> > I am getting the following when trying to write a dataframe to a file.
> >
> > I would appreciate any advice to where the problem lies.
> >
> > Thanks
> >
> > Ross Darnell
> > > write.table(all,file="agree.csv",row.names=F)
> > Error in "rownames<-"(*tmp*, value = row.names(x)) :
> > length of dimnames[1] not equal to array extent
> > > is.data.frame(all)
> > [1] TRUE
> > > dim(all)
> > [1] 854 18
> > > length(row.names(all))
> > [1] 854
> > >
> > > R.version
> > _
> > platform i686-pc-linux-gnu
> > arch i686
> > os linux-gnu
> > system i686, linux-gnu
> > status
> > major 1
> > minor 5.0
> > year 2002
> > month 04
> > day 29
> > language R
> > >
> >
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> > Send "info", "help", or "[un]subscribe"
> > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> >
>
> --
> 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 272860 (secr)
> Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list