[R] bug or bizarre feature?
Henrique Dallazuanna
wwwhsd at gmail.com
Mon Nov 30 20:24:54 CET 2009
Dim argument must be a integer, see the return of:
as.integer(slope*xdim)
Try this:
udim <- ceiling(max(slope*xdim,5))
On Mon, Nov 30, 2009 at 5:15 PM, Rupert Mazzucco <rmaz at gmx.net> 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 at 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list