I have a time series data in a data table format (let's say it has columns "date" and "y"), and I would like to cut the non-zero values of y into quartiles by date, so that each quartile gets the label 1-4, and the zero values to have a label of 0. So I know that if I just wanted to do this for all values of y, I would just run:

```
dt <- dt %>%
      group_by(date) %>%
      mutate(quartile = cut(y, breaks = 4, labels = (1:4)))

```

But I can't figure out how to do it to get labels 0-4, with 0 allocated to 0-values of y, and 1-4 being the quartiles in the non-zero values.

Edit: To clarify, what I want to do is the following: for each date, I would like to divide the values of y in that date into 5 groups: 1) y=0, 2) bottom 25% of y (in that date), 3) 2nd 25% of y, 3) 3rd 25% of y, 4) the top 25% of y.

Edit 2:
So I have found 2 more solutions for this:

```
dt[,quartile := cut(y, quantile(dt[y>0]$y, probs = 0:4/4),
              labels = (1:4)), by = date]

```

and 

```
dt %>%
    group_by(date) %>% 
    mutate(quartile = findInterval(y, quantile(dta[y>0]$y, 
                                                  probs= 0:4/4)))

```

But what both of these seem to do is to first calculate the break points for the entire data and then cut the data by date. But I want the break points to be calculated by date, since obs distribution can be different in different dates.