[R] someProblem in R-1.4.1

Uwe Ligges ligges at statistik.uni-dortmund.de
Wed May 22 12:14:53 CEST 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 replace
> > fix(M)
> > dimnames(M)[[2]]<-c("a","m","m","m","m") #works

During 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
> length

 nr <- 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,
> vito

Uwe 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

More information about the R-help mailing list