On Mar 14, 2007, at 7:05 AM, Alberto Monteiro wrote: > prod(U > 0) > > But this is not the most "elegant" solution, because there is > a function to check if all [and another to check if any] component > of a vector of booleans are [is] true: it's all(V) [resp. any(V)]. > So: > all(U > 0)
Just for the record, there is a actually a slight difference in the two calls of prod and all, which may or may not be important in the OP's case, in how they deal with NA's: > x<-c(-3,NA,2) > all(x>0) [1] FALSE > prod(x>0) [1] NA > x<-c(3,NA,2) > all(x>0) [1] NA > prod(x>0) [1] NA These are of course all as expected, just something to keep in mind. And in any case, "all" is as Alberto says more elegant, and semantically much more clear. (And not that it matters, but it is also somewhat faster). > Alberto Monteiro Haris Skiadas Department of Mathematics and Computer Science Hanover College ______________________________________________ [email protected] 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.
