Skip to main content
2 of 5
added 4 characters in body

Some code based on Rob's workaround of setting the negatives to zero and reconcile

# Re-reconciliate when zero values present
x=0 #Counter

# Loop until all positive
while(sum(hts.obj[[1]] <0) > 0){

  # Generate all time series
  hts.obj <- aggts(hts.obj)
  
  # Extract groups
  groups <- get_groups(hts.obj)
  
  # Overwrite negatives by zero
  hts.obj[hts.obj<0] <- 0
  
  # Reconcile
  hts.obj <- hts.obj %>%
    ts() %>%
    combinef(groups = groups, keep ="gts")
  
  # Count up
  x=x+1

  # Break after 10 loops
  if(x>=10)break

}

rm("x")

# Overwrite remaining negatives by zero
hts.obj[[1]][hts.obj[[1]]<0] <- 0

Its not super lean, but i hope it helps