Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
921 views
Welcome To Ask or Share your Answers For Others

1 Answer

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...