Skip to content
Prev 61271 / 63424 Next

Recycling in arithmetic operations involving zero-length vectors

Actually, sum(), all(), any(), prod() all return a _carefully considered_ result in the case of an empty vector. The sum over a disjoint union of sets should be the sum of the sums over each set, so if a set is empty, its contribution to the sum must be zero. Similarly, the product over an empty set is 1. Logical aggregate all() should be stable for "&" and any() for "|", hence all(logical(0))==TRUE and any(logical(0))==FALSE. 

-pd