In reply to Ajit de Silva.

You most certainly can do this in R. See, for example, solution on RosettaCode.org.