Select Page

Warning message:

In mean.default(polls.df):

argument is not numerical or logical: returning NA

 

I hate this message.  It has been the bane of me for far too long.  From what I understand, this error gets thrown at you when the console tries to compute something that it can’t.  In my case, the column for Name is not numeric.

Capture9

I read that this is a relatively new problem, as R before version 3.0 would just ignore the illogical request.  One way to get the right answer was with

colMeans(polls.df[,2:3])

Capture5.PNG

and

lapply(polls.df, mean, na.rm = TRUE)

Capture.PNG

Neither of these felt like particularly satisfactory ways to produce the mean.  Through this process, I came up with some rather weird outputs that are useless.  But I’m sure that looking back at these, from the future, will yield a good “What was I thinking?” moment, so I’ll include them.

Capture3

Capture6

Getting ggplot working was a tough hike as well.  I spent well over an hour trying to get a plot before I realized that, though I had installed the package, the library wasn’t loaded. Once I was able to get a basic plot working, I decided that I wanted to try to overlay both ABC_political_poll_results and NBC_political_poll_results onto one plot to show how the candidates vary between the two.  But try as I might, I was not successful, so I have only two separate, basic graphs to show the candidate’s results for each respective poll.

ggplot(polls.df, aes(x = Name, y = _political_poll_results)) + geom_point() + geom_point(data = polls.df, aes(x = Name, y = _political_poll_results))

Unfortunately I wasn’t really able to get anything else constructive done, though I did just realize that summary() worked fine at calculating the means.  That confuses me even more on why mean() wasn’t able to muster.

Captur33e.PNG