Reduce(function(x,acc){if (0==x%%3) c(x*x,acc) else acc}, 0:22, init=c(), right=T) 0 9 36 81 144 225 324 441