Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Finding start and end time index conditionally for xts dataset

$
0
0

I am trying to extract the start and end time index separately for all the labels and store them separately.

EDIT

As suggested in the comment I prepared an example dataset

data <- rnorm(11)

dates1 <- as.POSIXct("2019-03-18 10:30:00", tz = "CET") + 0:6*60
dates2 <- as.POSIXct("2019-03-19 08:30:00", tz = "CET") + 0:3*60
dates <- append(dates1, dates2)

R <- xts(x = data, order.by = dates) 
colnames(R) <- "R"
R$Label[1:7] <- 1
R$Label[8:11] <- 2

Output:

                           R Label
2019-03-18 10:30:00  1.193363635     1
2019-03-18 10:31:00 -0.558021057     1
2019-03-18 10:32:00  0.670440862     1
2019-03-18 10:33:00  0.073794492     1
2019-03-18 10:34:00 -0.416108940     1
2019-03-18 10:35:00 -0.596981420     1
2019-03-18 10:36:00  0.002006772     1
2019-03-19 08:30:00 -1.245200719     2
2019-03-19 08:31:00  0.417944923     2
2019-03-19 08:32:00  1.699169683     2
2019-03-19 08:33:00  0.861448103     2

Class of R is xts, zoo.

Now I would like to store the start and end time index for label 1 and two separately. I have many more data with more labels, so it needs to be automated. I would really appreciate if you can help. Thank you


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>