Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weighted_average function in calculations-latest_polls_weights.R #3

Open
mhoehle opened this issue May 6, 2017 · 0 comments
Open

Comments

@mhoehle
Copy link

mhoehle commented May 6, 2017

You may also want to consider using the summarise function instead of mutating an entire column and then extract the first element, which seems a bit clumsy. This also goes for the weighted_error function. For example:

weighted_average <- function(df_in,party_in,date_in){
  sz_avr <- df_in %>%
    tbl_df %>%
    filter(datum <= date_in) %>%
    filter(partei == party_in) %>%
    group_by(institut) %>%
    filter(datum == max(datum)) %>%
    ungroup() %>%
    summarise(roll_avr = sum(befragte * anteil) / sum(befragte)) %>% as.numeric
  sz_avr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant