Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning value to a variable that has a "dot" in the name

Tags:

r

I am new to R and was trying out the following code. To my surprise, assigning something to ret$log.id would actually caused to same value to be assigned to ret$log as well. E.g.,

 ret <- c()
 ret$log.id <- 'a'

Running the following would return "a"

ret$log

Is this what R supposed to do? I am hoping someone can give me some insight into this.

Thanks,

like image 437
defoo Avatar asked Dec 05 '22 22:12

defoo


1 Answers

Yes, the $ operator is doing some partial matching. You can explore the behavior a little with the following:

ret <- c()
ret$log.id <- "a"

ret$l #Returns "a"

ret$log.at <- "b"

Now see what's returned with the following:

ret$l
ret$log
ret$log.i
ret$log.a
like image 56
joran Avatar answered Dec 08 '22 15:12

joran