(Ted Harding) wrote:
On 28-Jul-08 17:52:31, Henrik Bengtsson wrote:
Use '&' for vectors and '&&' for scalars. Ditto applies to the OR
operator(s). /Henrik
What's wrong with using "&" for scalars? Surely it gives the
correct answer? Maybe it's simply a bit slower, or something?
Semantics are subtly different. a && b does not evaluate b if a is FALSE
(it is equivalent to if(a) then b else FALSE), so
> F & print("Hi")
[1] "Hi"
Error in F & print("Hi") :
operations are possible only for numeric or logical types
> F && print("Hi")
[1] FALSE
This is a bit synthetic, but it shows that there are differences in side
effects and error checking. In real life, an important case would be
when "a" is a check that "b" is at all computable.
-p
--
O__ ---- Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.