s-news
[Top] [All Lists]

problem in array

To: s-news@lists.biostat.wustl.edu
Subject: problem in array
From: "Weijie Cai" <wjcai2001@hotmail.com>
Date: Wed, 30 Oct 2002 15:23:41 -0500


Hi,
I got trouble when I tried to run the function I wrote below,
however, I cannot understand the error message:
"Problem in array: Missing value where logical needed"
I hope you can have a glance at my code and point out the problem.

ker<-function(x)  #x is a vector
{
       ind <- ifelse(vecnorm(x, p = 1) <= 1, 1, 0) #1-norm here
       y <- (15/16) * (1 - t(x) %*% x)^2 * ind
       y
}

ab<-function(y, n, hh)  #hh is a parameter, y is cbind of three vectors
{
       w <- matrix(0, n, n)
       a <- matrix(0, n, n)
       for(i in 1:n) {
               w[i, i] <- 15/32
               for(j in 1:i - 1) {
                       w[i, j] <- ker((y[i,  ] - y[j,  ])/hh)
               }
       }
       w <- w + t(w)
       for(i in 1:n) {
               w[i,  ] <- w[i,  ]/sum(w[i,  ])
       }
       a <- t(w) %*% w
       a
}

when I tried to run ab(mydata,n,2), mydata was cbind of 3 vectors like this
         int   exp exp2
[1646,]     1    24  576
[1647,]     1    17  289
[1648,]     1    45 2025

it reported error like this
Problem in array: Missing value where logical needed: if(length(data) < ll) {
       if(length(data) == 0)
               length(data) <- ll
       else {
               old <- data
               data[1:ll] <- old
               if(length(data) != ll)
                       stop("invalid initializing data")
       }
} else if(length(data) > ll) length(data) <- ll

I know it is bitter to look at somebody's codes, but I hope it is easy for you to point out the problem. Thank you so much!

regards,
weijie


_________________________________________________________________
Unlimited Internet access for only $21.95/month.  Try MSN! http://resourcecenter.msn.com/access/plans/2monthsfree.asp


<Prev in Thread] Current Thread [Next in Thread>
  • problem in array, Weijie Cai <=