[R] [R/S] strange

Erin Hodgess hodgess at gator.uhd.edu
Wed Sep 1 22:00:06 CEST 2004


Dear R and S People:

I have run across something very strange.  Here is a function that I wrote
for R:

boot1 <- function(y,method="f",p=1) {
n1 <- length(y)
n2 <- n1*p
n3 <- n2 - 1
a <- 0.5*(outer(1:n3,1:n3,function(x,y){n2 - pmax(x,y)}))
return(a)
}

and here is the R output:
> y1
[1] 9 8 7 3 6
> source("boot1.R")
> boot1(y=y1,p=4)
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18] [,19]
 [1,]  9.5  9.0  8.5  8.0  7.5  7.0  6.5  6.0  5.5   5.0   4.5   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
 [2,]  9.0  9.0  8.5  8.0  7.5  7.0  6.5  6.0  5.5   5.0   4.5   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
 [3,]  8.5  8.5  8.5  8.0  7.5  7.0  6.5  6.0  5.5   5.0   4.5   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
 [4,]  8.0  8.0  8.0  8.0  7.5  7.0  6.5  6.0  5.5   5.0   4.5   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
 [5,]  7.5  7.5  7.5  7.5  7.5  7.0  6.5  6.0  5.5   5.0   4.5   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
 [6,]  7.0  7.0  7.0  7.0  7.0  7.0  6.5  6.0  5.5   5.0   4.5   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
 [7,]  6.5  6.5  6.5  6.5  6.5  6.5  6.5  6.0  5.5   5.0   4.5   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
 [8,]  6.0  6.0  6.0  6.0  6.0  6.0  6.0  6.0  5.5   5.0   4.5   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
 [9,]  5.5  5.5  5.5  5.5  5.5  5.5  5.5  5.5  5.5   5.0   4.5   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
[10,]  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0  5.0   5.0   4.5   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
[11,]  4.5  4.5  4.5  4.5  4.5  4.5  4.5  4.5  4.5   4.5   4.5   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
[12,]  4.0  4.0  4.0  4.0  4.0  4.0  4.0  4.0  4.0   4.0   4.0   4.0   3.5   3.0   2.5   2.0   1.5   1.0   0.5
[13,]  3.5  3.5  3.5  3.5  3.5  3.5  3.5  3.5  3.5   3.5   3.5   3.5   3.5   3.0   2.5   2.0   1.5   1.0   0.5
[14,]  3.0  3.0  3.0  3.0  3.0  3.0  3.0  3.0  3.0   3.0   3.0   3.0   3.0   3.0   2.5   2.0   1.5   1.0   0.5
[15,]  2.5  2.5  2.5  2.5  2.5  2.5  2.5  2.5  2.5   2.5   2.5   2.5   2.5   2.5   2.5   2.0   1.5   1.0   0.5
[16,]  2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0  2.0   2.0   2.0   2.0   2.0   2.0   2.0   2.0   1.5   1.0   0.5
[17,]  1.5  1.5  1.5  1.5  1.5  1.5  1.5  1.5  1.5   1.5   1.5   1.5   1.5   1.5   1.5   1.5   1.5   1.0   0.5
[18,]  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0   0.5
[19,]  0.5  0.5  0.5  0.5  0.5  0.5  0.5  0.5  0.5   0.5   0.5   0.5   0.5   0.5   0.5   0.5   0.5   0.5   0.5
> 
which is as it should be.

Now I tried the same thing in S+
> y1
[1] 9 8 7 3 6
> source("boot1.R")
> boot1(y=y1,p=4)
Problem in FUN(rep(X, length(Y)), rep(Y, each = length(X))): Object "n2" not found 
Use traceback() to see the call stack
> 

I have no idea why it works in R but not in S+.

R 1.9.1 for Windows
S+ Version 6.2 for Windows.
Any help is appreciated!

Is this part of the difference in scoping, please?

Sincerely,
Erin M. Hodgess
Associate Professor
Dept. of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: hodgesse at uhd.edu




More information about the R-help mailing list