1

Is there anyway to use aggregate function with more than one input in dcast, or other functions can do this?

For example

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

dcast(aqm, month ~ variable, mean)

How can I calculate with mean of "value" weighted by day? Thanks in advance.

Yoki
  • 863
  • 4
  • 14
  • 26

1 Answers1

1

As akrun suggested, I checked the answer to other question and it worked:

> aqm %>%
+     select(month, day, variable, value) %>%
+     group_by(month, variable) %>%
+     summarise(weight_avg = weighted.mean(value,day)) %>%
+     spread(variable, weight_avg)
Yoki
  • 863
  • 4
  • 14
  • 26