vega:过滤每组的第 n 个

vega: filter nth of each group

如果我要按日期分组,我将如何筛选每个组的第 nth 个条目?

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {"url": "https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/seattle-temps.csv"},
  "mark": "point",
  "encoding": {
    "x": {"field": "date", "type": "temporal"},
    "y": {"field": "temp", "type": "quantitative"}
  }
}

编辑

让我们保持这个数据不可知,因为我的数据有很多列,我想要完整的行。

转换概述:

  1. 将时间转换为日期以进行分组。
  2. 按日期分组并在组内为每一行编号。
  3. 过滤第 nth 行。
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {"url": "https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/seattle-temps.csv"},
  "transform": [
    {"timeUnit": "yearmonthdate", "field": "date", "as": "date"},
    {
      "window": [{"op": "row_number", "as": "row"}],
      "groupby": ["date"]
    },
    {"calculate": "datum.index", "as":"newnew"},
    {"filter": "datum['row'] == 1"}
  ],
  "mark": "point",
  "encoding": {
    "x": {"field": "date", "type": "temporal"},
    "y": {"field": "temp", "type": "quantitative"}
  }
}

缺点是 vega 编辑器在添加 window 转换后变得非常慢。