I am trying to learn how to use the apply function, and I came across this tutorial: http://nsaunders.wordpress.com/2010/08/20/a-brief-introduction-to-apply-in-r/ , which seems clear and concise, but I immediately run into a problem. The very first example they give for demonstration are:
>
It seems very simple, but I thought I would try. Here is my result:
>
Needless to say, I'm lost on this ...
To provide additional information, I tried to make another example, given in the textbook, and got the correct result. The difference in this case was that the function was specifically specified in the apply function:
apply(m, 1:2, function(x) x/2) [,1] [,2] [1,] 0.5 5.5 [2,] 1.0 6.0 [3,] 1.5 6.5 [4,] 2.0 7.0 [5,] 2.5 7.5 [6,] 3.0 8.0 [7,] 3.5 8.5 [8,] 4.0 9.0 [9,] 4.5 9.5 [10,] 5.0 10.0
sessionInfo () is output below:
R version 2.15.3 (2013-03-01) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.3
And the output for conflicts (details = TRUE)
$.GlobalEnv [1] "edit" "mean" $`package:utils` [1] "edit" $`package:methods` [1] "body<-" "kronecker" $`package:base` [1] "body<-" "kronecker" "mean"