[R] Is a list an atomic object? (or is there an issue with the help page of ?tapply ?)

Bert Gunter bgunter.4567 at gmail.com
Tue Feb 14 20:05:36 CET 2017


Did you ever receive a reply to this?

Note that for your example:
> tapply(l,index,sum)
Error in FUN(X[[i]], ...) : invalid 'type' (list) of argument

A list is definitely not atomic (is.recursive(l) ).

So it looks like a "quirk" that FUN = unlist doesn't raise an error.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sat, Feb 4, 2017 at 4:17 AM, Tal Galili <tal.galili at gmail.com> 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.
>
>
>
>
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: Tal.Galili at gmail.com |
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
> ----------------------------------------------------------------------------------------------
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list