Calculate height (y value) for elements of a vector based on the heights of the previous several elements.

your chances of getting help with a solution will be increased immeasurably if you provide a reprex
FAQ: How to do a minimal reproducible example ( reprex ) for beginners