[R] Variable name with a '-'

peter dalgaard pdalgd at gmail.com
Sat Sep 10 19:31:27 CEST 2011


On Sep 10, 2011, at 16:33 , Adam Moore wrote:

> My statistics teacher wrote a textbook and included .rdata files for the
> problem set data. I downloaded these and opened one of them up. Then I used
> the ls() command, and it gave me this:
> 
>> ls()
> [1] "ex02-12"
> 
> However, when i try to use the object, it interprets it as ex02 - 12, and I
> get the following error:
> 
>> ex02-12
> Error: object 'ex02' not found
> 
> I don't know why my teacher has named everything this way, but she has. How
> do I access the object?

Use backticks, that's what they are for: `ex02-12`. Or get("ex02-12"). Possibly save it under a new name to preserve your sanity. 

> 
> Thanks,
> 
> Adam Moore
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
"Døden skal tape!" --- Nordahl Grieg



More information about the R-help mailing list