[R] weighted average grouped by variables
Massimo Bressan
massimo.bressan at arpa.veneto.it
Thu Nov 9 15:45:23 CET 2017
hi thierry
thanks for your reply
yes, you are right, your solution is more straightforward
best
Da: "Thierry Onkelinx" <thierry.onkelinx at inbo.be>
A: "Massimo Bressan" <massimo.bressan at arpa.veneto.it>
Cc: "r-help" <r-help at r-project.org>
Inviato: Giovedì, 9 novembre 2017 15:17:31
Oggetto: Re: [R] weighted average grouped by variables
Dear Massimo,
It seems straightforward to use weighted.mean() in a dplyr context
library(dplyr)
mydf %>%
group_by(date_time, type) %>%
summarise(vel = weighted.mean(speed, n_vehicles))
Best regards,
ir. Thierry Onkelinx
Statisticus / Statistician
Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkelinx at inbo.be
Kliniekstraat 25, B-1070 Brussel
www.inbo.be
///////////////////////////////////////////////////////////////////////////////////////////
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey
///////////////////////////////////////////////////////////////////////////////////////////
Van 14 tot en met 19 december 2017 verhuizen we uit onze vestiging in Brussel naar het Herman Teirlinckgebouw op de site Thurn & Taxis.
Vanaf dan ben je welkom op het nieuwe adres: Havenlaan 88 bus 73, 1000 Brussel.
///////////////////////////////////////////////////////////////////////////////////////////
--
------------------------------------------------------------
Massimo Bressan
ARPAV
Agenzia Regionale per la Prevenzione e
Protezione Ambientale del Veneto
Dipartimento Provinciale di Treviso
Via Santa Barbara, 5/a
31100 Treviso, Italy
tel: +39 0422 558545
fax: +39 0422 558516
e-mail: massimo.bressan at arpa.veneto.it
------------------------------------------------------------
[[alternative HTML version deleted]]
More information about the R-help
mailing list