I've come across this pitfall as well, i.e. mistakenly assigning to a
scalar and assuming that R would simply expand to a vector by the number
of data points meeting the condition.
Is it safe to assume in James case that R is using the last data point under the theory of recycling? Would like to understand the process a bit better.