R does not find a variable

This is my code:

Density curve

ggplot(datr, aes(x=Sim)) + geom_density()

R can't find the object Sim although when I do a head command it is listed and I tied to be sure that it was numeric. Can someone tell me what my error is and how to correct it?

1 1,2,11,7.35,7.55,1,1,1
2 2,4,11,4.68,4.22,2,1,1
3 3,2,11,7.06,6.1,3,1,1
4 4,4,11,3.97,3.13,4,1,1
5 5,4,11,3.3,3.02,5,1,1
6 6,2,11,6.74,6.67,6,1,1

ggplot(datr, aes(x=Sim)) + geom_density()
Error in eval(expr, envir, enclos) : object 'Sim' not found

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.


If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.

Sim should be a column in datr. From your head call, it looks like it didn't get read in properly somehow—it's all one character variable called SUBJECT.TIME.CMT.Sim.obs.prev_subject.rep.peak of numbers in CSV format. Maybe you need read.csv instead of read.table?

1 Like

Yes, that resolved my problem. Read.(table connected all the variables so they could not be distinguished.
Read.csv put everything in the proper format.

ok, I will prior to my next post. My question was answered by a community member with the old format.