thanks, that workaround, well, works!

what are you working on with the rewrite?  just efficiency?  or major
changes in functionality/interface?

thanks,
mike

On Wed, Jul 30, 2008 at 7:10 PM, hadley wickham <[EMAIL PROTECTED]> wrote:

> On Wed, Jul 30, 2008 at 12:41 PM, mfrumin <[EMAIL PROTECTED]> wrote:
> >
> > I want the column that is never going to actually have the '(all)' level
> to
> > not become of type factor.  continuing the example:
> >
> > chick_m$diet = as.integer(as.character(chick_m$diet))
> > is.factor(chick_m$diet) #returns FALSE
> > is.factor(cast(subset(chick_m, time == 0), diet + chick ~ time, mean,
> > margins="diet")$diet) #returns TRUE
> >
> > does that make sense?  the way it works now, it totally screws things up
> > when the column for which you get margins is not a factor.  in my case, a
> > date column.
>
> Oh, I see what you mean.  That's definitely a bug and I've added it my
> todo list.  Unfortunately it's not a trivial fix, and I'm currently
> working on a major rewrite of reshape (among other things), so it may
> be a while before I get to it
>
> I can only offered this rather hackish work around:
>
> chick_m$diet <- as.integer(as.character(chick_m$diet))
> out <- cast(subset(chick_m, time == 0), diet + chick ~ time, mean,
> margins="diet")
>
>
>
> restore <- function(cast, molten) {
>  vars <- names(out)[sapply(out, function(x) is.factor(x) && sum(x ==
> "(all)") == 0)]
>
>  for(var in vars) {
>    m <- match(as.character(cast[[var]]), as.character(molten[[var]]))
>
>    cast[var] <- molten[m, var]
>  }
>  cast
> }
>
> restore(out, chick_m)
>
> Hadley
>
>
> --
> http://had.co.nz/
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to