vendredi 2 janvier 2015

How to write a for loop in R with multiple criteria and datetimes

I am trying to write a for loop that will subset out data that meets certain criteria. Date/times less than 7 minutes apart that also have two different directions (up&down or down&up), and with a length difference less than 4. This is what the dataset looks like.



Sample Data




> DateTime Length Direction
> 4/3/2014 14:43 90 Up
> 4/3/2014 14:45 92 Down
> 4/3/2014 14:46 97 Up
> 4/3/2014 14:49 199 Up
> 4/3/2014 14:50 200 Up
> 4/3/2014 14:55 202 Down


I formatted the date:



data$DateTime<-as.POSIXlt(data$DateTime,format="%m/%d/%y %H:%M",tz="US/Pacific")



I was thinking I could use difftime in a for loop to calculate the time differences and then have additional if statements for the other criteria but I am having trouble setting it up. Can anyone provide any help?


Aucun commentaire:

Enregistrer un commentaire