0

I'm wondering if someone can please help me figure out how to filter data for the first time instance after each minute on the dot.
As an example, if my data frame is

as follows

I want row 1 and row 13 (the first time instances after cycles of 60 seconds), but nothing in between.

I cannot use modulus division by 60 because most instances do not occur right on the dot.

amonk
  • 1,769
  • 2
  • 18
  • 27
Anna
  • 825
  • 1
  • 11
  • 19
  • 2
    Welcome to StackOverflow. Please take a look at these tips on how to produce a [minimum, complete, and verifiable example](http://stackoverflow.com/help/mcve), as well as this post on [creating a great example in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Perhaps the following tips on [asking a good question](http://stackoverflow.com/help/how-to-ask) may also be worth a read. – lmo May 23 '17 at 14:24

1 Answers1

0

Given your dataframe df,create a new time (time2)

 df$time2<-as.numeric(df$time)-60
 time2[time2<0]#keep only the negative ones
 first<-head(df[which(df$time2<0)],n=1)#gives the 1st element
 last<-tail(df[which(df$time2<0)+1],n=1)#idem for the last element +1
amonk
  • 1,769
  • 2
  • 18
  • 27
  • Thank you! Just to confirm, for your second line, am I creating a subset of df that deletes every row in which df$time2 is not negative? And then in the third and fourth lines, what is test2? – Anna May 23 '17 at 17:11
  • @Anna Replies to your questions: yes! Test2 was just a mistake. Now corrected and answer updated. Let me know if it works – amonk Jun 14 '17 at 13:01
  • Hey @agerom, this only gives me the first and last element of my entire table, but does not give me the first instance of every minute. However, I have figured out how to query minute-by-minute data directly from my database – Anna Jun 19 '17 at 18:06