0

I have the following columns in a dataframe which difference between each row is 0.012 s :

Time
 0
 0.012
 0.024
 0.036
 0.048
 0.060
 0.072
 0.084
 0.096
 0.108

I want to come up with intervals starting from beginning increasing by 0.030, so intervals or time window of every 0.03 later to be used in group by.

chessosapiens
  • 2,870
  • 9
  • 31
  • 52
  • Could you please include failed attempts such that those can be ruled out? – NelsonGon Sep 12 '19 at 11:32
  • 1
    i was going to use Cut , or findinterval but i don't have any number of blocks, the only thing i have this 0.03 window length – chessosapiens Sep 12 '19 at 11:34
  • Alright, could you please copy and paste what the data would look like after transformation? I'm personally more of a look at the data person(someone else probably is so it might help them too). – NelsonGon Sep 12 '19 at 11:36

1 Answers1

2

You can try findInterval like

findInterval(df$Time, seq(min(df$Time), max(df$Time), 0.03))
#[1] 1 1 1 2 2 3 3 3 4 4

We can also use cut

breaks <- seq(min(df$Time), max(df$Time), 0.03)
cut(df$Time, c(breaks, Inf), labels = breaks, include.lowest = TRUE)
#[1] 0    0    0    0.03 0.03 0.03 0.06 0.06 0.09 0.09

data

df <- structure(list(Time = c(0, 0.012, 0.024, 0.036, 0.048, 0.06, 
0.072, 0.084, 0.096, 0.108)), class = "data.frame", row.names = c(NA, -10L))
Ronak Shah
  • 355,584
  • 18
  • 123
  • 178