mercredi 25 février 2015

R: which apply function for conditioned iteration?

I'm new to R and I'm wondering which the fastest and most elegant way to do the iteration I'm going to describe. I have a big dataframe formatted like this:



date_time value1 value2
01-02-1986 00:00 100.120 200.150
01-02-1986 00:01 100.125 201.120
...
01-02-1986 23:59 100.950 190.130
02-02-1986 00:00 103.110 108.200
...


so there are one date and two numeric columns and the rows go on minute by minute.


For each day I need to take df$value1 at given times (say 10:00, 11:00, 15:00), for each pass ceil it to its first decimal, find out the highest value above this in the next Y minutes and put it in a matrix so that I will end up with something like:



<dd-mm-yy> <highest at time 1> <highest at time 2> <highest at time 3>
...
<dd-mm-yy> <highest at time 1> <highest at time 2> <highest at time 3>


I have a vector of the HH:MM I need and a subset of df that contains only the pertinent hours (10:00 to 10:59, 11:00 to 11:59 and 15:00 to 15:59) but now I'm stuck on the iteration.


Is there a way to do this without a for/if cycle rolling the whole array?


Thank you for your help.


Aucun commentaire:

Enregistrer un commentaire