Proably ole Faq 7.21 again. You are using floating point numbers and
expecting coercion to result in upward rounding.
My guess is that if you use trunc(udim) you will get a different number.
Yep:
> trunc(udim)
[1] 115
On Nov 30, 2009, at 2:15 PM, Rupert Mazzucco wrote:
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
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.