model-time in R take a sample based on ID column

Hi R Com

have the following code:

library(tidymodels)
library(modeltime)
library(tidyverse)
library(timetk)

Collect data

data <- walmart_sales_weekly %>%
select(id, Date, Weekly_Sales) %>%
set_names(c("ID", "date", "value"))

data

sample <- data %>%
mutate(item_id = ID) %>%
filter(as.numeric(item_id) %in% 1:3)

unique(sample$item_id)

i want a sample of 3 item_id with the " filter(as.numeric(item_id %in% 1:3) " but when i run unique(sample$item_id) I get only 2 unique values?

thank

Might be because:

unique(data$ID)
# [1] 1_1  1_3  1_8  1_13 1_38 1_93 1_95

Regards,
Grzegorz

Because what? not sure i follow :slight_smile:

Also i cannot find the functions:
split_nested_timeseries
extend_timeseries
nest:timeseires

have installed modeltime
library(modeltime)

the split_nested_timeseries function is showed here:

library(tidyverse)
library(timetk)
library(modeltime)

nested_data_tbl <- walmart_sales_weekly %>%
select(id, Date, Weekly_Sales) %>%
set_names(c("id", "date", "value")) %>%

Step 1: Extends the time series by id

extend_timeseries(
.id_var = id,
.date_var = date,
.length_future = 52
) %>%

Step 2: Nests the time series into .actual_data and .future_data

nest_timeseries(
.id_var = id,
.length_future = 52
) %>%

Step 3: Adds a column .splits that contains training/testing indicies

split_nested_timeseries(
.length_test = 52
)

nested_data_tbl

Helpers: Getting the Train/Test Sets

extract_nested_train_split(nested_data_tbl, .row_id = 1)

Error in split_nested_timeseries(., .length_test = 52) :
could not find function "split_nested_timeseries"

Because in the original data set there is no other values than: 1_1, 1_3 , 1_8, 1_13, 1_38, 1_93, 1_95.

Let's assume, you want to remove "1_" and the remaining chars are: 1, 3, 8, etc.
If you are searching for values between 1:3, there is no much, just 1 and 3.

Hope it helps,
Grzegorz

ahh so if i rename the id column to 1,2,3,4,5,6,7,8,9,10 it works? or what is the solution to this?

Thanks!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.