From ligges at statistik.tu-dortmund.de  Tue Sep 14 12:02:04 2010
From: ligges at statistik.tu-dortmund.de (Uwe Ligges)
Date: Tue, 14 Sep 2010 12:02:04 +0200
Subject: [Rd] value returned by by()
In-Reply-To: <87vd69b8f6.fsf@kolob.sebmags.homelinux.org>
References: <87vd69b8f6.fsf@kolob.sebmags.homelinux.org>
Message-ID: <4C8F481C.8010502@statistik.tu-dortmund.de>

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,
>



[Rd] value returned by by()
Uwe Ligges