[R] = vs. ==?

Gad Abraham gabraham at csse.unimelb.edu.au
Wed Apr 16 00:58:22 CEST 2008


Linn wrote:
> Hi
> Could anyone please explain to me the difference between the = and the ==?
> I'm quite new to R and I've tried to find out but didn't get any wiser...

"=" is the assignment operator as in

 > x = 3
 > x
[1] 3

(but use the "<-" operator instead, see a post by Bill Venables a few 
days ago called ``What to use for assignment, " = " or " <- "?'')

whereas "==" is the binary operator for testing equality, as in

 > x == 3
[1] TRUE

Have a look at any introductory R book or at the R intro at 
http://cran.r-project.org/doc/manuals/R-intro.html

-- 
Gad Abraham
Dept. CSSE and NICTA
The University of Melbourne
Parkville 3010, Victoria, Australia
email: gabraham at csse.unimelb.edu.au
web: http://www.csse.unimelb.edu.au/~gabraham



More information about the R-help mailing list