Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # --------------------------------------
- # Construct xts data.
- # --------------------------------------
- rows_to_build <- 6
- dates <- seq(
- as.POSIXct("2019-01-01 09:01:00"),
- length.out = rows_to_build,
- by = "1 min",
- tz = "CEST"
- )
- master_decision = c(
- # - Clarification what "for-loop" should do:
- 3, # Keep (missing [3] above)
- 2, # Keep (missing [2] above)
- 2, # Delete due to [2] on line above.
- 3, # Keep (missing [3] above)
- 3, # Delete due to [3] on line above.
- 2 # Keep (missing [2] above)
- )
- data <- data.frame(master_decision)
- xts1 <- xts(x = data, order.by = dates)
- rm(list = ls()[! ls() %in% c("xts1")]) # Only keep [xts1].
- # ------------------------------------------------------------
- # For loop with purpose to remove duplicates that are grouped.
- # ------------------------------------------------------------
- for (i in 2:nrow(xts1)) {
- if(xts1[[i]] == xts1[[i-1]]) {
- xts1[-c(i)]
- }
- }
- master_decision
- 2019-01-01 09:01:00 3
- 2019-01-01 09:02:00 2
- 2019-01-01 09:03:00 2
- 2019-01-01 09:04:00 3
- 2019-01-01 09:05:00 3
- 2019-01-01 09:06:00 2
- master_decision
- 2019-01-01 09:01:00 3
- 2019-01-01 09:02:00 2
- 2019-01-01 09:03:00 2
- 2019-01-01 09:04:00 3
- 2019-01-01 09:06:00 2
- 2019-01-01 09:01:00 3
- 2019-01-01 09:02:00 2
- 2019-01-01 09:04:00 3
- 2019-01-01 09:06:00 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement