[R] ave(x, y, FUN=length) produces character output when x is character
Mike Miller
mbmiller+l at gmail.com
Thu Dec 25 10:23:34 CET 2014
On Thu, 25 Dec 2014, Jeff Newmiller wrote:
> You have written a lot, Mike, as though we did not know it. You are not
> the only one with math and multiple computing languages under your belt.
I'm not assuming that you and Bert don't know things, but I do expect to
have a wider audience -- when I search for things, sometimes I find my
postings from 10 years ago. I'm probably not the only one.
> The point Bert made is that the concept that a matrix IS-A vector is not
> just an implementation detail in R... it helps the practitioner keep
> straight why things like a[3] is perfectly valid when a is a matrix, and
> why
>
> a*a
> [,1] [,2]
> [1,] 1 9
> [2,] 4 16
>
> is true. I understand why you are uncomfortable with it, as I was once,
> but this is how R works so you are only impeding your own effectiveness
> by clinging to theory on this point.
Sorry, your concepts aren't helping me and I'm not uncomfortable with what
R is doing. In fact, what I wrote earlier is that R seems to be much like
Octave/MATLAB, which I have used even more than I've used R. The use of
what Octave calls "fortran indexing" is an example. We can refer to
matrix element a[3] in R or element a(3) in Octave and we're referring to
the same element. It's also the third element of vec(a). That doesn't
mean that 'a' is a vector. R says that it is not a vector. That doesn't
confuse me. I can refer to the third element of a matrix even if the
matrix is not a vector.
I don't understand how your concept helps in understanding a*a. It's an
element-by-element product (also called Hadamard product). In Octave it
would be a.*a. The matrix product in R is a%*%a and in Octave it is a*a.
I find nothing confusing about any of this and I don't see how conceiving
of 'a' as a vector helps at all.
The difference between our concepts is that this makes no sense within
your framework where you think of a matrix as being a vector:
> a <- matrix(1:4, 2,2)
> is.vector(a)
[1] FALSE
But to me it makes perfect sense because 'a' is a matrix and a matrix is
not a vector. We might say that it contains a vector, or that the
elements of the matrix are constructed from the elements of a vector, but
not that the matrix is a vector. It is a different class of object:
> class(a)
[1] "matrix"
Mike
More information about the R-help
mailing list