R matrix handling expressions aren't evaluated in a function or a "for" loop - Column extract doesn't seem to work

Posted by Sal Leggio on Stack Overflow See other posts from Stack Overflow or by Sal Leggio
Published on 2011-01-17T17:49:30Z Indexed on 2011/01/17 17:53 UTC
Read the original article Hit count: 198

I have an R matrix named ddd. When I enter this, everything works fine:

i <- 1 shapiro.test(ddd[,y]) ad.test(ddd[,y]) stem(ddd[,y]) print(y)

The calls to Shapiro Wilk, Anderson Darling, and stem all work, and extract the same column.

If I put this code in a "for" loop, the calls to Shapiro Wilk, and Anderson Darling stop working, while the the stem & leaf call and the print call continue to work.

for (y in 7:10) { shapiro.test(ddd[,y]) ad.test(ddd[,y]) stem(ddd[,y]) print(y) }

The decimal point is 1 digit(s) to the right of the |

0 | 0 0 | 899999 1 | 0

[1] 7

The same thing happens if I try and write a function. SW & AD do not work. The other calls do.

D <- function (y) { + shapiro.test(ddd[,y]) + ad.test(ddd[,y]) + stem(ddd[,y]) + print(y) }

D(9)

The decimal point is at the |

9 | 000 9 | 10 | 00000

[1] 9

Why don't all the calls behave the same way?

© Stack Overflow or respective owner

Related posts about r

    Related posts about lazy-evaluation