Multiple functions in reshape2

512 views
Skip to first unread message

paul

unread,
Sep 14, 2010, 3:47:24 AM9/14/10
to manipulatr
Hi,

Somehow, I can't get multiple functions to work in reshape2. See here:

names(airquality) <- tolower(names(airquality))
aqm <- melt(airquality, id=c("month", "day"), na.rm=TRUE)
acast(aqm, month ~ variable, c(mean, sd))

This leads to an error:

Error in vaggregate(.value = value, .group = overall, .fun =
fun.aggregate, :
could not find function ".fun"

When I elaborate this a little, a call like:

acast(aqm, month ~ variable, function(x){c(M=mean(x), SD=sd(x))})

leads to another error:

Error in attributes(.Data) <- c(attributes(.Data), attrib) :
dims [product 20] do not match the length of object [40]

Both versions are apparently no longer working. How can I apply more
than one function to a molten data frame with reshape2? Did I miss
something in the documentation?

Best,
Paul

Hadley Wickham

unread,
Sep 14, 2010, 9:20:26 PM9/14/10
to paul, manipulatr
Hi Paul,

I guess you missed the bit in the announcement where I said this is no
longer supported. This simplifies the code quite a bit, and is one of
the factors that has lead to the big speed up. Could you describe more
fully what you're trying to do? There might be an alternative
approach that will do what you want.

Hadley

> --
> You received this message because you are subscribed to the Google Groups "manipulatr" group.
> To post to this group, send email to manip...@googlegroups.com.
> To unsubscribe from this group, send email to manipulatr+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/manipulatr?hl=en.
>
>

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Paul Metzner

unread,
Sep 15, 2010, 1:49:14 AM9/15/10
to Hadley Wickham, manipulatr
I'm sorry to flood you with questions that are apparently all answered in the announcement. I used reshape to build me a data.frame that included everything I needed to create nice plots with ggplot, e.g. means, standard errors, confidence intervals, etc. I think I'll try now and build seperate sets, since geom_errorbar() can operate on a different dataset than the 'original' geom, as far as I know. I guess I'll come back to this list if things don't work out…

Best,
Paul

---
Paul Metzner

Manfred-von-Richthofen-Str. 13
12101 Berlin
Deutschland

Tel.: +49-(0)30-6730-9220
Mobil: +49-(0)17-8288-1059

paul.m...@gmail.com
http://amor.rz.hu-berlin.de/~metznerp/

Hadley Wickham

unread,
Sep 15, 2010, 8:19:11 AM9/15/10
to Paul Metzner, manipulatr
Could you provide a fuller example? I'm happy to be proven wrong that
functions with multiple returns are no longer necessary. Given your
description I suspect ddply will provide a more convenient interface.

Hadley

Reply all
Reply to author
Forward
0 new messages