SHARE
TWEET

Untitled

a guest Mar 19th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dailyData <- data.frame(
  2.   DateTime = seq.POSIXt(lubridate::ymd_hms('2019-01-01', truncated=3),
  3.                         lubridate::ymd_hms('2019-01-07', truncated=3),
  4.                         by='day'),
  5.   Name = 'Daily TS'
  6.   )
  7.  
  8. allHours <- data.frame(
  9.   DateTime = seq.POSIXt(lubridate::ymd_hms('2019-01-01', truncated=3),
  10.                         lubridate::ymd_hms('2019-01-07 23:00:00'),
  11.                         by='hour')
  12. )
  13.  
  14. hourlyData <- allHours %>%
  15.   dplyr::mutate( Name = 'Hourly TS' )
  16.  
  17. allData <- rbind( dailyData, hourlyData )
  18.      
  19. head( allData, n=15 )
  20.               DateTime      Name
  21. 1  2019-01-01 00:00:00  Daily TS
  22. 2  2019-01-02 00:00:00  Daily TS
  23. 3  2019-01-03 00:00:00  Daily TS
  24. 4  2019-01-04 00:00:00  Daily TS
  25. 5  2019-01-05 00:00:00  Daily TS
  26. 6  2019-01-06 00:00:00  Daily TS
  27. 7  2019-01-07 00:00:00  Daily TS
  28. 8  2019-01-01 00:00:00 Hourly TS
  29. 9  2019-01-01 01:00:00 Hourly TS
  30. 10 2019-01-01 02:00:00 Hourly TS
  31. 11 2019-01-01 03:00:00 Hourly TS
  32. 12 2019-01-01 04:00:00 Hourly TS
  33. 13 2019-01-01 05:00:00 Hourly TS
  34. 14 2019-01-01 06:00:00 Hourly TS
  35. 15 2019-01-01 07:00:00 Hourly TS
  36.      
  37. expanded_BAD <- allData %>%
  38.   dplyr::right_join( allHours, by='DateTime' ) %>%
  39.   tidyr::fill( dplyr::everything(), .direction='down' ) %>%
  40.   dplyr::arrange( Name, DateTime )
  41.      
  42. head(expanded_BAD, n=15)
  43.               DateTime      Name
  44. 1  2019-01-01 00:00:00  Daily TS
  45. 2  2019-01-02 00:00:00  Daily TS
  46. 3  2019-01-03 00:00:00  Daily TS
  47. 4  2019-01-04 00:00:00  Daily TS
  48. 5  2019-01-05 00:00:00  Daily TS
  49. 6  2019-01-06 00:00:00  Daily TS
  50. 7  2019-01-07 00:00:00  Daily TS
  51. 8  2019-01-01 00:00:00 Hourly TS
  52. 9  2019-01-01 01:00:00 Hourly TS
  53. 10 2019-01-01 02:00:00 Hourly TS
  54. 11 2019-01-01 03:00:00 Hourly TS
  55. 12 2019-01-01 04:00:00 Hourly TS
  56. 13 2019-01-01 05:00:00 Hourly TS
  57. 14 2019-01-01 06:00:00 Hourly TS
  58. 15 2019-01-01 07:00:00 Hourly TS
  59.      
  60. dailyData_expanded_GOOD <- dailyData %>%
  61.   dplyr::right_join( allHours, by='DateTime' ) %>%
  62.   tidyr::fill( dplyr::everything(), .direction='down' )
  63.      
  64. head(dailyData_expanded_GOOD, n=15)
  65.               DateTime    Value
  66. 1  2019-01-01 00:00:00 Daily TS
  67. 2  2019-01-01 01:00:00 Daily TS
  68. 3  2019-01-01 02:00:00 Daily TS
  69. 4  2019-01-01 03:00:00 Daily TS
  70. 5  2019-01-01 04:00:00 Daily TS
  71. 6  2019-01-01 05:00:00 Daily TS
  72. 7  2019-01-01 06:00:00 Daily TS
  73. 8  2019-01-01 07:00:00 Daily TS
  74. 9  2019-01-01 08:00:00 Daily TS
  75. 10 2019-01-01 09:00:00 Daily TS
  76. 11 2019-01-01 10:00:00 Daily TS
  77. 12 2019-01-01 11:00:00 Daily TS
  78. 13 2019-01-01 12:00:00 Daily TS
  79. 14 2019-01-01 13:00:00 Daily TS
  80. 15 2019-01-01 14:00:00 Daily TS
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top