This function converts data in a data frame or tibble into a time series format. It is designed to
work with data generated from tidy_
distribution functions. The function can return time series data, pivot it
into long format, or both.
Arguments
- .data
A data frame or tibble to be converted into a time series format.
- .return_ts
A logical value indicating whether to return the time series data. Default is TRUE.
- .pivot_longer
A logical value indicating whether to pivot the data into long format. Default is FALSE.
Value
The function returns the processed data based on the chosen options:
If
ret_ts
is set to TRUE, it returns time series data.If
pivot_longer
is set to TRUE, it returns the data in long format.If both options are set to FALSE, it returns the data as a tibble.
Details
The function takes a data frame or tibble as input and processes it based on the specified options. It performs the following actions:
Checks if the input is a data frame or tibble; otherwise, it raises an error.
Checks if the data comes from a
tidy_
distribution function; otherwise, it raises an error.Converts the data into a time series format, grouping it by "sim_number" and transforming the "y" column into a time series.
Returns the result based on the chosen options:
If
ret_ts
is set to TRUE, it returns the time series data.If
pivot_longer
is set to TRUE, it pivots the data into long format.If both options are set to FALSE, it returns the data as a tibble.
See also
Other Utility:
check_duplicate_rows()
,
quantile_normalize()
,
tidy_mcmc_sampling()
,
util_beta_aic()
,
util_binomial_aic()
,
util_cauchy_aic()
,
util_chisq_aic()
,
util_exponential_aic()
,
util_f_aic()
,
util_gamma_aic()
,
util_generalized_beta_aic()
,
util_generalized_pareto_aic()
,
util_geometric_aic()
,
util_hypergeometric_aic()
,
util_inverse_burr_aic()
,
util_inverse_pareto_aic()
,
util_inverse_weibull_aic()
,
util_logistic_aic()
,
util_lognormal_aic()
,
util_negative_binomial_aic()
,
util_normal_aic()
,
util_paralogistic_aic()
,
util_pareto1_aic()
,
util_pareto_aic()
,
util_poisson_aic()
,
util_t_aic()
,
util_triangular_aic()
,
util_uniform_aic()
,
util_weibull_aic()
,
util_zero_truncated_binomial_aic()
,
util_zero_truncated_geometric_aic()
,
util_zero_truncated_negative_binomial_aic()
,
util_zero_truncated_poisson_aic()
Examples
# Example 1: Convert data to time series format without returning time series data
x <- tidy_normal()
result <- convert_to_ts(x, FALSE)
head(result)
#> # A tibble: 6 × 1
#> y
#> <dbl>
#> 1 1.99
#> 2 0.416
#> 3 -0.362
#> 4 -0.282
#> 5 0.404
#> 6 -0.694
# Example 2: Convert data to time series format and pivot it into long format
x <- tidy_normal()
result <- convert_to_ts(x, FALSE, TRUE)
head(result)
#> # A tibble: 6 × 1
#> y
#> <dbl>
#> 1 -0.912
#> 2 -0.732
#> 3 -0.582
#> 4 0.204
#> 5 -0.661
#> 6 -2.18
# Example 3: Convert data to time series format and return the time series data
x <- tidy_normal()
result <- convert_to_ts(x)
head(result)
#> y
#> [1,] -0.1348973
#> [2,] 0.6769697
#> [3,] -0.5048327
#> [4,] -0.8381438
#> [5,] -2.9578102
#> [6,] 1.1051425