Help with tsibble

Hi,

I am learning time series and started with converting data into tsibble object. Data contains three variables: Date ( in the form of 2020 05) showing year and month; Brands (as A, B, C) and Sales ( as quantity)

I was trying to do the following:

df <- df%>%
  mutate(Date = yearmonth(Date)) %>%
  as_tsibble(key = `Brands`, index = `Date`)

But I get this error:
Error: A valid tsibble must have distinct rows identified by key and index. i Please use duplicates() to check the duplicated rows.

However, there are no duplicates in the data.

Thanks for your help!

I'm skeptical that there are no duplicates in the data.
How would you prove this.
If instead of your code that fails to create the tsibble you did

df%>%
  mutate(Date = yearmonth(Date)) %>% {table(.$Date,.$Brands)}

what would be the result ?

1 Like

Interesting....Thanks @nirgrahamuk! Yes, I do see duplicates now. I deleted a Location variable before converting into tsibble, thinking I am only interested in Brands as key and corresponding Sales forgetting about unique combinations where location and Brands combination kept it as unique rows earlier.

So, now that I have included it back in the game, how can I specify a combination of two variables as key for tsibble. In this case, Location and Brands. The below code doesn't seem to work.

as_tsibble(key = c(Location, Brands), index = Date)

could you be more precise/explicit about how your problem shows itself?
I just wrote code that looks like that, and it works fine on my data...

I just found 2 duplicates even with the combinations....probably that is the problem. I will update you after fixing these duplicates...hopefully it will work then.

Thank you so much on helping me with this!

It does work now...Thanks @nirgrahamuk with the help on duplicates!

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