[R] bug or bizarre feature?
Rupert Mazzucco
rmaz at gmx.net
Mon Nov 30 20:15:00 CET 2009
Hello,
I'm running into a very strange problem:
> xrange <- c(-2.5,2.5)
> xdim <- 100
> mobility <- 0.1
> slope <- 1.16
> urange <- slope*xrange
> udim <- max(slope*xdim,5)
> du <- (urange[2]-urange[1])/udim
> uvec <- urange[1]+(1:udim-0.5)*du
> # type dependent weight function
> ckern <- array(0,dim=c(udim,udim))
> diag(ckern) = wfun(uvec,slope,mobility)
Error in `diag<-`(`*tmp*`, value = c(0.992300064325398, 0.990746129315703, :
replacement diagonal has wrong length
It turns out that the array ckern has the wrong size for some reason.
Instead of 116x116, it is only 115x115.
> udim
[1] 116
> length(uvec)
[1] 116
> length(wfun(uvec,slope,mobility))
[1] 116
> dim(ckern)
[1] 115 115
The "taint" or whatever that is, is even transferable
> n <- udim
> n
[1] 116
> ckern <- array(0,dim=c(n,n))
> dim(ckern)
[1] 115 115
> m <- n
> m
[1] 116
> ckern <- array(0,dim=c(m,m))
> dim(ckern)
[1] 115 115
But when I set it explicitly, it does what it should:
> n <- 116
> n
[1] 116
> ckern <- array(0,dim=c(n,n))
> dim(ckern)
[1] 116 116
Note that the funny behavior seems to be peculiar to this one value of slope <- 1.16,
many others work fine, e.g.
> slope <- 1.08
> urange <- slope*xrange
> udim <- max(slope*xdim,5)
> du <- (urange[2]-urange[1])/udim
> uvec <- urange[1]+(1:udim-0.5)*du
> # type dependent weight function
> ckern <- array(0,dim=c(udim,udim))
> diag(ckern) = wfun(uvec,slope,mobility)
> dim(ckern)
[1] 108 108
This is R 2.10.0, but also happened in 2.8.0. Can anybody tell me what
is going on here, and how I can get my array to be the right size?
Thanks,
Rupert
More information about the R-help
mailing list