Hi all, This seems a very strange problem, but I'm running R-1.4.1 so, probably it has been solved in the 1.5.0 version (unfortunatly I can neither download the new version nor see the archive). Assignement of column names in a matrix, works just after editing it:> M<-matrix(0,10,5) > dimnames(M)[[2]]<-c("a","m","m","m","m") #sayError: more elements supplied than there are to replace> fix(M) > dimnames(M)[[2]]<-c("a","m","m","m","m") #worksFurthermore the following problem also seems related: nr<-20 M<-matrix(0,nr,5) for(i in 1:nr){ ........some functions......... M[i,]<-c(....) #5-dimensional vector } It works until to i=10 and then the following message appears: Error in "[<-"(*tmp*, i, , value =c(......., : number of items to replace is not a multiple of replacement length This sound me very strange, because if some errors there are, it should not work also for i<=10. The loop perfectly works with nr=10 , but it doesn't so for nr=15, 30, for instance. Many thanks for your help best, vito -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 22 May 2002, vito muggeo wrote:> Hi all, > This seems a very strange problem, but I'm running R-1.4.1 so, probably it > has been solved in the 1.5.0 version (unfortunatly I can neither download > the new version nor see the archive). > > Assignement of column names in a matrix, works just after editing it: > > > M<-matrix(0,10,5) > > dimnames(M)[[2]]<-c("a","m","m","m","m") #say > Error: more elements supplied than there are to replaceThat's incorrect. Try> dimnames(M)NULL so you are trying to replace the second element of NULL. colnames(M)<-c("a","m","m","m","m") #say will work, as will dimnames(M) <- list(NULL, c("a","m","m","m","m"))> > fix(M)That adds colnames, as it uses the internals of edit.data.frame.> > dimnames(M)[[2]]<-c("a","m","m","m","m") #worksThis is still the same in 1.5.0. -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
vito muggeo wrote:> > Hi all, > This seems a very strange problem, but I'm running R-1.4.1 so, probably it > has been solved in the 1.5.0 version (unfortunatly I can neither download > the new version nor see the archive). > > Assignement of column names in a matrix, works just after editing it: > > > M<-matrix(0,10,5) > > dimnames(M)[[2]]<-c("a","m","m","m","m") #say > Error: more elements supplied than there are to replace > > fix(M) > > dimnames(M)[[2]]<-c("a","m","m","m","m") #worksDuring fix()-ing the matrix got column names, and dimnames() got a list of two elements (it was not before!). Please read ?dimnames. The *second* example is not documented to work. You can always assign names as described on the help page: dimnames(M) <- list(NULL, c("a","m","m","m","m")) Or just use colnames(M) <- c("a","m","m","m","m")> Furthermore the following problem also seems related: > nr<-20 > M<-matrix(0,nr,5) > for(i in 1:nr){ > ........some functions......... > M[i,]<-c(....) #5-dimensional vector > } > It works until to i=10 and then the following message appears: > Error in "[<-"(*tmp*, i, , value =c(......., : > number of items to replace is not a multiple of replacement > lengthnr <- 20 M <- matrix(0, nr, 5) for(i in 1:nr) M[i,] <- 1:5 works for me. Can you provide an example?> This sound me very strange, because if some errors there are, it should not > work also for i<=10. > The loop perfectly works with nr=10 , but it doesn't so for nr=15, 30, for > instance. > > Many thanks for your help > best, > vitoUwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._