[R] the underscore ("_") in variable name

mohd zamri root at sirius.ftsm.ukm.my
Mon Oct 2 08:35:54 CEST 2000

new to R and starting to learn to program R. The underscore ("_") did some
suprising result. e.g

> c <- c(1,2,3,4,5)
> mean(c)
[1] 3
> c_mean <- mean(c)
> c
[1] 3

having some experience in C, I thought the underscore is "always" valid in
variable name. totally confuse me. Reread the R-FAQ a few times, and found
on pg. 7 foot-note which states that;

   the underscore character "_" is an alllowable synonym for the left
   pointing assignment operator "<-", ...........
it is appear that R parse  "c_mean <-  mean(c)" as "c <- mean <- mean(c)",
which explain the result.


I believe it would be helpful if this point be make clear on the FAQ, and
not mention as a footnote. What is a proper naming convention and a few
example of valid/invalid name for variables.

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list