Reputation: 23
I’m working on an analysis using Vector autoregression (VAR) model. I’m working with data that has the date format in yyyy-mm-dd hh:mm:ss. But the examples I find online are mostly YYYY-MM format.
Example:
y1<- ts(y$y1, start= c(2020, 5), frequency = 12)
Additionally, the data I’m trying to use is from twitter and the information is not consistent in the timeframe. Also, I did check to make sure I have no duplicated rows.
How would I perform a VAR analysis on the data in the following format?
Upvotes: 0
Views: 178
Reputation: 10637
This is to create a tsibble
needed for fable
to do VAR with a resolution of seconds and only one row per time point:
library(tidyverse)
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
library(fable)
#> Loading required package: fabletools
tribble(
~Datetime, ~A, ~B, ~C,
"2014-02-27 17:28:11", 626, 0,0,
"2014-02-27 17:28:11", 626, 0,0,
"2014-02-19 14:16:20", 0,0,1
) %>%
mutate(Datetime = parse_datetime(Datetime, format = "%Y-%m-%d %H:%M:%z")) %>%
distinct(Datetime, .keep_all = TRUE) %>%
as_tsibble(index = Datetime)
#> # A tsibble: 2 x 4 [12h 12m] <UTC>
#> Datetime A B C
#> <dttm> <dbl> <dbl> <dbl>
#> 1 2014-02-18 18:16:00 0 0 1
#> 2 2014-02-27 06:28:00 626 0 0
Created on 2021-09-13 by the reprex package (v2.0.1)
Upvotes: 0