[R] Is a list an atomic object? (or is there an issue with the help page of ?tapply ?)
Martin Maechler
maechler at stat.math.ethz.ch
Mon Feb 20 14:31:49 CET 2017
>>>>> Hervé Pagès <hpages at fredhutch.org>
>>>>> on Tue, 14 Feb 2017 17:10:05 -0800 writes:
> Hi, tapply() will work on any object 'X' that has a length
> and supports single-bracket subsetting. These objects are
> sometimes called "vector-like" objects. Atomic vectors,
> lists, S4 objects with a "length" and "[" method,
> etc... are examples of "vector-like" objects.
> So instead of saying
> X: an atomic object, typically a vector.
> I think it would be more accurate if the man page was
> saying something like
> X: a vector-like object that supports subsetting with
> `[`, typically an atomic vector.
Thank you, Hervé!
Actually (someone else mentioned ?)
only length(X) and split(X, <group>) need to work,
and as split() itself is an S3 generic function, X can be even
more general... well depending on how exactly you understand
"vector-like".
So I would go with
X: an R object for which a ‘split’ method exists. Typically
vector-like, allowing subsetting with ‘[’.
Martin
> H.
> On 02/04/2017 04:17 AM, Tal Galili wrote:
>> In the help page of ?tapply it says that the first
>> argument (X) is "an atomic object, typically a vector."
>>
>> However, tapply seems to be able to handle list
>> objects. For example:
>>
>> ###################
>>
>> l <- as.list(1:10) is.atomic(l) # FALSE index <-
>> c(rep(1,5),rep(2,5)) tapply(l,index,unlist)
>>
>>> tapply(l,index,unlist)
>> $`1` [1] 1 2 3 4 5
>>
>> $`2` [1] 6 7 8 9 10
>>
>>
>> ###################
>>
>> Hence, does it mean a list an atomic object? (which I
>> thought it wasn't) or is the help for tapply needs
>> updating? (or some third option I'm missing?)
>>
>> Thanks.
More information about the R-help
mailing list