[R] ave(x, y, FUN=length) produces character output when x is character

Mike Miller mbmiller+l at gmail.com
Thu Dec 25 05:45:51 CET 2014


On Wed, 24 Dec 2014, Jeff Newmiller wrote:

> On December 24, 2014 6:49:47 PM PST, Mike Miller <mbmiller+l at gmail.com> wrote:
>
>> On Wed, 24 Dec 2014, Mike Miller wrote:
>>
>>> Also, regarding the sacred text, "x A numeric." is a bit terse.  The 
>>> same text later refers to length(x), so I suspect that "A numeric" is
>>
>>> short for "A numeric vector", but that might not mean "a vector of 
>>> 'numeric' type."
>>
>>
>> I just realized that numeric type includes integer so that anything of 
>> type integer also is type numeric.  I'm working on another message.
>
>
> But all numeric types in R are vectors. So although it might be a good 
> idea to be redundant to aid beginners, the phrase "a numeric" is 
> accurate.


Interesting, but the data seem to contradict your theory.  Here are two 
examples, one with a numeric matrix, the other with a numeric array, and 
both of them run in ave().

> x <- matrix(1:4, 2,2)

> is.numeric(x)
[1] TRUE

> is.vector(x)
[1] FALSE

> ave(x, gl(2,2))
      [,1] [,2]
[1,]  1.5  3.5
[2,]  1.5  3.5


> x <- as.array(1:4)

> is.numeric(x)
[1] TRUE

> is.vector(x)
[1] FALSE

> ave(x, gl(2,2))
[1] 1.5 1.5 3.5 3.5


So maybe slightly more documentation for ave() would be helpful even for 
non-beginners like yourself.

Thanks.

Mike

-- 
Michael B. Miller, Ph.D.
University of Minnesota
http://scholar.google.com/citations?user=EV_phq4AAAAJ



More information about the R-help mailing list