R: fix intersection bug (#20).
R: refactor common code for union and intersection (#20).