[R] re sultant column names from reshape::cast, with a fun.aggregate vector

From: mfrumin <michael_at_frumin.net>
Date: Tue, 17 Jun 2008 07:40:44 -0700 (PDT)

try this:

scores.melt = data.frame(grade = floor(runif(100, 1,10)), variable = 'score', value = rnorm(100));

cast(scores.melt, grade ~ variable, fun.aggregate = c(mean, length))

it has the nice column names of:

  grade score_mean score_length

1     1  0.08788535            8
2     2  0.16720313           15
3     3  0.41046299            7
4     4  0.13928356           13

...

but now try this:

cast(scores.melt, grade ~ variable, fun.aggregate = c(mean, function(x) sum(x < 0)))

and you get a huge mess:

  grade score_mean score_function.x..sum.x...0.

1     1  0.08788535                            4
2     2  0.16720313                            6
3     3  0.41046299                            2
4     4  0.13928356                            5

I would think that something like this would fix it up, but no dice:

 cast(scores.melt, grade ~ variable, fun.aggregate = c(mean, num.neg = function(x) sum(x < 0)))

that is, why not look at names(fun.aggregate)? or am I missing something?

thanks,
Mike

I would think that

-- 
View this message in context: http://www.nabble.com/resultant-column-names-from-reshape%3A%3Acast%2C-with-a-fun.aggregate-vector-tp17910885p17910885.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_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.
Received on Tue 17 Jun 2008 - 14:57:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 17 Jun 2008 - 16:30:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive