Skip to content

someProblem in R-1.4.1

3 messages · vito muggeo, Brian Ripley, Uwe Ligges

#
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:
Error: more elements supplied than there are to replace
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

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:

            
That's incorrect.  Try
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"))
That adds colnames, as it uses the internals of edit.data.frame.
This is still the same in 1.5.0.
#
vito muggeo wrote:
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")
nr <- 20
 M <- matrix(0, nr, 5)
 for(i in 1:nr) M[i,] <- 1:5

works for me. Can you provide an example?
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._