Error: "Can't convert a double vector to function"

Hello,

R doesn't let me execute a stat_summary function when drawing a bar graph.

I load a csv file into a dataframe:
df <- read.csv("spelling.csv")

The commands for the graph:
bar <- ggplot(df, aes(Group, Errors))
bar + stat_summary(fun = mean, geom = "bar", fill = "White", colour = "Black")

The stat_summary causes the problem. R Studio throws the following error message:
Warning message:
Computation failed in stat_summary():
Can't convert a double vector to function

Why do I get this error message? How can I fix this?

I would appreciate any help.

Thanks!

Best, Andreas

My best guess is that you have 'poisoned' your environment by saving some numbers into a variable named mean, and stat_summary is getting this rather than the base::mean function.

what do you see when you type mean into the console ?

mean

you can reassign mean to base::mean with

mean <- base::mean
1 Like

Thank you so much, nirgrahamuk! You gave the right hint!

I removed the variables created in previous assignments from the environment. After that, the stat_summary function could be executed without problem. In order to remove the variables, I used:

rm(list=ls())

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.