SHARE
TWEET

Untitled

a guest Jun 19th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     3,      # Keep (there no [3] above)
  16.     2,      # Keep (there no [2] above)
  17.     2,      # Deleted due to no [2] on line above.
  18.     3,      # Keep (there no [2] above)
  19.     3,      # Deleted due to no [3] on line above.
  20.     2       # Keep (no [2] above)
  21. )
  22.  
  23. data <- data.frame(master_decision)
  24. xts1 <- xts(x = data, order.by = dates)
  25.  
  26.  
  27. rm(list = ls()[! ls() %in% c("xts1")]) # Only keep [xts1].
  28.  
  29.  
  30. # ------------------------------------------------------------
  31. # For loop with purpose to remove duplicates that are grouped.
  32. # ------------------------------------------------------------
  33.  
  34. for (i in 2:nrow(xts1)) {
  35.     if(xts1[[i]] == xts1[[i-1]]) {
  36.         xts1[-c(i)]
  37.     }
  38. }
  39.      
  40. master_decision
  41. 2019-01-01 09:01:00               3
  42. 2019-01-01 09:02:00               2
  43. 2019-01-01 09:03:00               2
  44. 2019-01-01 09:04:00               3
  45. 2019-01-01 09:05:00               3
  46. 2019-01-01 09:06:00               2
  47.      
  48. master_decision
  49. 2019-01-01 09:01:00               3
  50. 2019-01-01 09:02:00               2
  51. 2019-01-01 09:03:00               2
  52. 2019-01-01 09:04:00               3
  53. 2019-01-01 09:06:00               2
  54.      
  55. 2019-01-01 09:01:00               3
  56. 2019-01-01 09:02:00               2
  57. 2019-01-01 09:04:00               3
  58. 2019-01-01 09:06:00               2
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top