[Rd] value returned by by()

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Sep 14 12:02:04 CEST 2010


It returns a list with athe class attribut set to "by", just use:

x <- by(.....)
unclass(x)


Uwe Ligges


On 14.09.2010 00:11, Seb wrote:
> Hi,
>
> I noticed that by() returns an object of class 'by', regardless of what
> its argument 'simplify' is.  ?by says that it always returns a list if
> simplify=FALSE, yet by.data.frame shows:
>
> ---<--------------------cut here---------------start------------------->---
> function (data, INDICES, FUN, ..., simplify = TRUE)
> {
>      if (!is.list(INDICES)) {
>          IND<- vector("list", 1L)
>          IND[[1L]]<- INDICES
>          names(IND)<- deparse(substitute(INDICES))[1L]
>      }
>      else IND<- INDICES
>      FUNx<- function(x) FUN(data[x, , drop = FALSE], ...)
>      nd<- nrow(data)
>      ans<- eval(substitute(tapply(1L:nd, IND, FUNx, simplify = simplify)),
>          data)
>      attr(ans, "call")<- match.call()
>      class(ans)<- "by"
>      ans
> }
> <environment: namespace:base>
> ---<--------------------cut here---------------end--------------------->---
>
> One could force a list by wrapping it around an lapply(by.object, "["),
> but this is not possible if the object contains S4 objects.  How does
> one force a list in those cases?
>
>
> Cheers,
>



More information about the R-devel mailing list