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

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

On Thu, 25 Dec 2014, Mike Miller wrote:

> I was going to ask a question about it how to test that an object is a 
> vector, but then I found this:
> "is.vector() does not test if an object is a vector. Instead it returns 
> TRUE only if the object is a vector with no attributes apart from names. 
> Use is.atomic(x) || is.list(x) to test if an object is actually a 
> vector."
> From here:
> http://adv-r.had.co.nz/Data-structures.html#vectors

But here...


...I read, "Note that factors are *not* vectors" (emphasis theirs), yet...

> d <- gl(2,2)

> is.factor(d)
[1] TRUE

> is.atomic(d) || is.list(d)
[1] TRUE

> is.list(d)

> is.atomic(d)
[1] TRUE

> is.vector(d)

So the factor is not a vector according to R documentation, but it is a 
vector according to the Wickham test, and it is not a vector according to 
is.vector().  Admittedly, the latter seems not to mean much to the R 
experts.  Maybe a factor is just a vector with additional attributes.


More information about the R-help mailing list