Summarize to find the average of different factors

Hi. Another question about the polling analysis.
I'm now trying to calculate the average margin of error of each polling websites to find out the confidence that a poll result would reflect the result. Here is what I have.

poll %>%
select(Poll, MoE) %>%
group_by(Poll) %>%
summarise(avg = mean(.data[[poll]], na.rm = TRUE))

And the error comes out:

Error: Must subset the data pronoun with a string

This should be pretty simple but I kind of stuck in summarise part. Thank you in advance for any hints.

just guessing because I can't run your code on your data.
but does this work better?

poll %>%
  select(Poll, MoE) %>%
  group_by(Poll) %>%
  summarise(avg = mean(MoE, na.rm = TRUE))

well, if you scraped the table, then MoE values like -- will have caused your MoE to be a character type, for which there is no concept of mean(). therefore consider cleaning your character variable and converting it to a number. readr::parse_number() may be useful

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

I appreciate your reply.
It doesn't work and ends up with another error

argument is not numeric or logical: returning NA

The data is similar to the first polling data in the link.