Language settings and "Can't convert a double vector to function"

When I load csv files into a dataframe, it happens that the a header of a column shows strange characters, e.g.: ï.. as in 'ï..profScore'

My statistics instructor thought it might be a language setting issue. What we checked in R Studio on my laptop is:
[1] "LC_COLLATE=German_Switzerland.1252;LC_CTYPE=German_Switzerland.1252;LC_MONETARY=German_Switzerland.1252;LC_NUMERIC=C;LC_TIME=German_Switzerland.1252"

We changed that with:
[1] "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252"

But the problem persists. And when I close and restart R Studio, the settings are back to German_Switzerland again. How could I fix that permanently to English or LANG = "en_US.UTF-8"?

If the issue with the strange characters is not related to language settings, what else could cause this problem? And how could I fix that?

And finally, I cannot draw a bar graph (perhaps this problem is related to the issues mentioned above, that's why I'm mentioning it here as well).
I load a csv file into a dataframe:
df <- read.csv("swahili.csv")

The commands for the graph:
bar <- ggplot(df, aes(Group, ï..profScore))
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.


Best, Andreas

A solution to the problem with the characters is to re-encode the csv as UTF-8. To do so, yo read it in in Notepad++ where you can change the encoding from UTF-8-BOM to UTF-8. Then save that re-encoded csv file in the working directory of R. When reading it in in R, the unwanted characters are not present anymore.

An alternative is to add the following to the read.csv function in R:
df <- read.csv("filename.csv", fileEncoding = "UTF-8-BOM")

1 Like

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.