Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dcast fun.aggregate parameters

Tags:

r

reshape2

In the R package reshape2, does the dcast() function parameter fun.aggregate= have the ability to accept parameters itself?

For instance:

dcast(dataFrame, x ~ y, value.var = 'z', fun.aggregate = mean(na.rm = TRUE))

I'm asking because I use my own function for the fun.aggregate parameter, and I'd rather not hard code the parameters into a growing list of functions.

This website is great; thanks everyone.

like image 715
RGH Avatar asked Nov 01 '13 18:11

RGH


1 Answers

Like many functions in R, dcast has a ... argument that is typically used to pass additional arguments on to a function. In fact, at ?dcast, you'll find this line in the "arguments section":

... further arguments are passed to aggregating function

Thus, the correct way of writing your example would be:

dcast(dataFrame, x ~ y, value.var = 'z', fun.aggregate = mean, na.rm = TRUE)
like image 198
A5C1D2H2I1M1N2O1R2T1 Avatar answered Sep 23 '22 16:09

A5C1D2H2I1M1N2O1R2T1