by zmmmmm · 13y ago · 0 comments
> is.vector("a")
[1] TRUE
This might seem like nitpicking but it leads to a world of confusion when programmers used to languages with scalars start trying to use R that way and it took me several months of confusion and weird bugs before I finally clicked and started understanding R better.For example, if you told somebody familiar with, say, PHP to add 2 to each element in a vector, they would likely break out the oh-so-familiar for loop to iterate over each element and apply the transform. This is completely suboptimal in R, as you could just do vector + 2 and receive the exact same thing.
crossprod(y, crossprod(A, y)) * V
where A was nxn, y was nx1, and V was an arbitrary matrix throws an error while drop(crossprod(y, crossprod(A, y))) * V
works.