[R] generating new data with for loop
Gordon J Holtslander
gordon.holtslander at usask.ca
Tue Jun 9 23:11:17 CEST 2009
I'm new at R ...
I've not done for loops in R - so this is very new to me.
One of our students has a data frame that contains two columns data
1. unixtime time of an event (in unix time - #of seconds)
2. duration of event in seconds.
We need to create new data - the unixtime (seconds) that these events
occurred.
We want to create a for loop (or nested for loops) that goes through the
first column, and then creates a new unixtime value for each second of
duration for that event
In a single row of data -
if the duration was three seconds one iteration of this loop should create
these values
unixtime
unixtime = unixtime +1
unixtime = unixtime +1
unixtime = unixtime +1
I need these four data values (and all the successive data values created by
the loop(s)) saved into a new dataframe
How do I get R to create a new data object and add data to it on each
interation of the for loop.
My test for loops only save the data from last iteration of the loop.
Am I missing something really simple?
Any recommended reference on loop and control structures in R?
Thanks,
Gord
--
Gordon J. Holtslander
gordon.holtslander at usask.ca
Dept. of Biology
University of Saskatchewan
tel 306 966-4433
fax 306 966-4461
More information about the R-help
mailing list