7

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.

4

1 回答 1

10

像 R 中的许多函数一样,dcast它有一个...参数,通常用于将附加参数传递给函数。实际上,在 处?dcast,您会在“参数部分”中找到这一行:

... 进一步的参数被传递给聚合函数

因此,编写示例的正确方法是:

dcast(dataFrame, x ~ y, value.var = 'z', fun.aggregate = mean, na.rm = TRUE)
于 2013-11-01T18:16:37.263 回答