R write to csv file
R change of loop
R change in loop
added picture and small edits
Merged changes from Beth and Linton.