R matrix handling expressions aren't evaluated in a function or a "for" loop - Column extract doesn't seem to work
- by Sal Leggio
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?