[R] Problem with outer()

Christofer Bogaso bogaso.christofer at gmail.com
Wed Sep 22 10:18:07 CEST 2010


Dear all, I have following piece of codes:

xx <- seq(-2,2, length.out=11)
mat1 <- cbind(rep(43, 5), rnorm(5))
mat2 <- cbind(rep(53, 5), rnorm(5))
outer(c(1,-1), xx, function(x,y) {
                      AA <- sign(x)
                      BB <- sign(y)
                      CC <- abs(y)
                      DD1 <- mat1[,2]-mat1[1,1]
                      DD2 <- mat2[,2]-mat2[1,1]
                      EE <- (DD1 - 0) *AA + DD2*BB
                      res1 <- mean(EE)/mat1[1,1]
                      res2 <- ifelse(quantile(EE/mat1[1,1], 0.05) >
-0.65, quantile(EE/mat1[1,1], 0.05), paste("< -0.65"))
                      return(paste(res1, res2, sep="--"))
                    }
                  )

While running this code I am getting warnings as well as error:

> outer(c(1,-1), xx, function(x,y) {
+                       AA <- sign(x)
+                       BB <- sign(y)
+                       CC <- abs(y)
+                       DD1 <- mat1[,2]-mat1[1,1]
+                       DD2 <- mat2[,2]-mat2[1,1]
+                       EE <- (DD1 - 0) *AA + DD2*BB
+                       res1 <- mean(EE)/mat1[1,1]
+                       res2 <- ifelse(quantile(EE/mat1[1,1], 0.05) >
-0.65, quantile(EE/mat1[1,1], 0.05), paste("< -0.65"))
+                       return(paste(res1, res2, sep="--"))
+                     }
+                   )
Error in dim(robj) <- c(dX, dY) :
  dims [product 22] do not match the length of object [1]
In addition: Warning messages:
1: In (DD1 - 0) * AA :
  longer object length is not a multiple of shorter object length
2: In DD2 * BB :
  longer object length is not a multiple of shorter object length

I am able to trace the warning, which comes from multiplication with
AA & BB. However could not find the correct way to tackle this
warning. Neither the error. Can somebody help me where I was wrong?

Thanks



More information about the R-help mailing list