corrected typos and replaces a section of r code that was pasteed
incorrectly.