Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. # --------------------------------------
  2. # Construct xts data.
  3. # --------------------------------------
  4.  
  5. rows_to_build <- 6
  6.  
  7. dates <- seq(
  8. as.POSIXct("2019-01-01 09:01:00"),
  9. length.out = rows_to_build,
  10. by = "1 min",
  11. tz = "CEST"
  12. )
  13.  
  14. master_decision = c(
  15. # - Clarification what "for-loop" should do:
  16. 3, # Keep (missing [3] above)
  17. 2, # Keep (missing [2] above)
  18. 2, # Delete due to [2] on line above.
  19. 3, # Keep (missing [3] above)
  20. 3, # Delete due to [3] on line above.
  21. 2 # Keep (missing [2] above)
  22. )
  23.  
  24. data <- data.frame(master_decision)
  25. xts1 <- xts(x = data, order.by = dates)
  26.  
  27.  
  28. rm(list = ls()[! ls() %in% c("xts1")]) # Only keep [xts1].
  29.  
  30.  
  31. # ------------------------------------------------------------
  32. # For loop with purpose to remove duplicates that are grouped.
  33. # ------------------------------------------------------------
  34.  
  35. for (i in 2:nrow(xts1)) {
  36. if(xts1[[i]] == xts1[[i-1]]) {
  37. xts1[-c(i)]
  38. }
  39. }
  40.  
  41. master_decision
  42. 2019-01-01 09:01:00 3
  43. 2019-01-01 09:02:00 2
  44. 2019-01-01 09:03:00 2
  45. 2019-01-01 09:04:00 3
  46. 2019-01-01 09:05:00 3
  47. 2019-01-01 09:06:00 2
  48.  
  49. master_decision
  50. 2019-01-01 09:01:00 3
  51. 2019-01-01 09:02:00 2
  52. 2019-01-01 09:03:00 2
  53. 2019-01-01 09:04:00 3
  54. 2019-01-01 09:06:00 2
  55.  
  56. 2019-01-01 09:01:00 3
  57. 2019-01-01 09:02:00 2
  58. 2019-01-01 09:04:00 3
  59. 2019-01-01 09:06:00 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement