View source: R/transform_to_transactional.R
transform_to_transactional | R Documentation |
Converts a data frame with a ID column and all different date columns to a transactional data frame with three columns: ID, Date and Value. The function removes zero_demand observations to minimize storage size.
transform_to_transactional( df, keep_columns = TRUE, non_zero_demand = FALSE, start = NULL, end = NULL, freq = NULL )
df |
A dataframe or matrix containing sales on a particular date. Columns stand for time observations |
keep_columns |
A boolean stating if the function returns the original columns. Default is TRUE. |
non_zero_demand |
A boolean stating if the function should returns zero observations. Default is FALSE. |
start |
A date object indicating the starting date in the transactional df. NOTE 1: Only considered if keep_columns is set to FALSE. NOTE 2: If keep_columns is set to false, the start parameter should be given along with end or freq |
end |
A date object indicating the last date on the transcational df |
freq |
The frequency of the observated observations. Can be numeric, or string (eg 'day', 'week', '2 weeks', 'month', '2 months', 'quater', 'year') |
A data frame or matrix with three columns: ID, Date and Value
Filotas Theodosiou
dates <- c('2019-07-01', '2019-07-02', '2019-07-03', '2019-07-01') stores <- c('AM','AC') example_df <- data.frame( t1 = c(15, 12), t2 = c(30, 40 ), t3 = c(0, 5), t4 = c(21, 30) ) rownames(example_df) <- stores tr_df <- transform_to_transactional(example_df, keep_columns = TRUE) # Keeps current columns tr_df_dates <- transform_to_transactional(example_df, keep_columns = FALSE, start = as.Date(dates[1]), freq = 'day' )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.