new r code for simulating data