[R] assign values

Roger Bivand Roger.Bivand at nhh.no
Sun Nov 13 22:25:33 CET 2005


On Sun, 13 Nov 2005, Robert wrote:

> 
> 
> Peter Dalgaard <p.dalgaard at biostat.ku.dk> wrote:
> Robert writes:
> 
> > Professor,
> > What does if ((x=2)) 2 mean?
> > Thanks,
> > Robert
> 
> it assigns 2 to x, then uses the result (i.e. whether it is non-zero)
> as the condition for the if() construct. So in this case, the
> condition is always TRUE and the result is always 2.
> 
> I see. 
> 
> > if ((x=2)) 2
> [1] 2
> > if ((x=0)) 2
> > 

Look at the text above "(i.e. whether it is non-zero)", and:

as.logical(seq(-2,2,1))

and then at your result - numeric x with value 0 is being cast to logical 
FALSE, so this is as described.

> 
> 
> 		
> ---------------------------------
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list