Below is an animated Gif that should show the way R code can be embedded in a Lyx document and compiled to form the document on reshaping data mentioned in a previous post. Click on the image to run the animation. Click here to see the final document reshapingdata
The Lyx document can be downloaded here. Change the extension from .doc to lyx.