1

I want to know the difference between

x.char = c("A", "B", "C")

and

x = c("A", "B", "C")

when should I use x.char instead of x?

thanks

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
Jiyoon Go
  • 59
  • 3
  • 1
    I don't see why people are downvoting this. It's a valid question to ask, and a common misunderstanding among people coming from other languages. – Hong Ooi Jun 17 '17 at 13:11
  • Related: [What does the dot mean in R – personal preference, naming convention or more?](https://stackoverflow.com/questions/7526467/what-does-the-dot-mean-in-r-personal-preference-naming-convention-or-more) – Henrik Jun 17 '17 at 13:22
  • ...and perhaps: [The State of Naming Conventions in R](https://journal.r-project.org/archive/2012-2/RJournal_2012-2_Baaaath.pdf). – Henrik Jun 17 '17 at 13:29

1 Answers1

4

It looks like you're coming from programming languages where the dot (.) means something. Eg in C++, C# and Java, x.foo means the foo member of the x class.

In R, . is not anything special. It's just another character that you can use in a variable name. In your example, x.char is a variable, and x is another variable. There's no difference between the two statements, except that they refer to different variables.

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • thank you so much! I have studied javascript before haha – Jiyoon Go Jun 17 '17 at 12:27
  • `.` is actually important in the naming of functions (as you know). But that's probably a bit advanced for this question. – Rich Scriven Jun 17 '17 at 12:33
  • 1
    @RichScriven that's more of a defect with S3 than anything. Eg `as.data.frame.foo` could be the `as` method for `data.frame.foo`, the `as.data` method for `frame.foo`, the `as.data.frame` method for `foo`, or just a plain old variable. – Hong Ooi Jun 17 '17 at 13:09