(add-lag ds source-col k target-col)Add a lagged version of a column to a dataset.
Creates a new column with values shifted forward by k positions, filling the first k positions with nil (tracked as missing values).
Example: (add-lag ds :Beer 4 :Beer_lag4) ;; Adds column :Beer_lag4 where row i contains Beer[i-4], nil for i<4
Add a lagged version of a column to a dataset. Creates a new column with values shifted forward by k positions, filling the first k positions with nil (tracked as missing values). Example: (add-lag ds :Beer 4 :Beer_lag4) ;; Adds column :Beer_lag4 where row i contains Beer[i-4], nil for i<4
(add-lags ds source-col lags)(add-lags ds source-col lags opts)Add multiple lagged versions of a column to a dataset.
lags — map of {k target-col-name} or vector of lags (auto-named as source_lag{k})
Options: :drop-missing — drop rows with nil values in any of the new lag columns (default true)
Examples: ;; Map form with custom names (add-lags ds :Beer {4 :Beer_lag4, 8 :Beer_lag8, 12 :Beer_lag12})
;; Vector form with auto-named columns (:Beer_lag1, :Beer_lag2, etc.) (add-lags ds :Beer [1 2 3 4])
;; Keep nils (don't drop rows) (add-lags ds :Beer [1 2 3 4] {:drop-missing false})
Add multiple lagged versions of a column to a dataset.
lags — map of {k target-col-name} or vector of lags (auto-named as source_lag{k})
Options:
:drop-missing — drop rows with nil values in any of the new lag columns (default true)
Examples:
;; Map form with custom names
(add-lags ds :Beer {4 :Beer_lag4, 8 :Beer_lag8, 12 :Beer_lag12})
;; Vector form with auto-named columns (:Beer_lag1, :Beer_lag2, etc.)
(add-lags ds :Beer [1 2 3 4])
;; Keep nils (don't drop rows)
(add-lags ds :Beer [1 2 3 4] {:drop-missing false})(add-lead ds source-col k target-col)Add a lead (forward-shifted) version of a column to a dataset.
Creates a new column with values shifted backward by k positions, filling the last k positions with nil (tracked as missing values).
Example: (add-lead ds :Beer 4 :Beer_lead4) ;; Adds column :Beer_lead4 where row i contains Beer[i+4], nil for last 4 rows
Add a lead (forward-shifted) version of a column to a dataset. Creates a new column with values shifted backward by k positions, filling the last k positions with nil (tracked as missing values). Example: (add-lead ds :Beer 4 :Beer_lead4) ;; Adds column :Beer_lead4 where row i contains Beer[i+4], nil for last 4 rows
(add-leads ds source-col leads)(add-leads ds source-col leads opts)Add multiple lead (forward-shifted) versions of a column to a dataset.
leads — map of {k target-col-name} or vector of leads (auto-named as source_lead{k})
Options: :drop-missing — drop rows with nil values in any of the new lead columns (default true)
Examples: ;; Map form with custom names (add-leads ds :Beer {4 :Beer_lead4, 8 :Beer_lead8})
;; Vector form with auto-named columns (:Beer_lead1, :Beer_lead2, etc.) (add-leads ds :Beer [1 2 3 4])
;; Keep nils (don't drop rows) (add-leads ds :Beer [1 2 3 4] {:drop-missing false})
Add multiple lead (forward-shifted) versions of a column to a dataset.
leads — map of {k target-col-name} or vector of leads (auto-named as source_lead{k})
Options:
:drop-missing — drop rows with nil values in any of the new lead columns (default true)
Examples:
;; Map form with custom names
(add-leads ds :Beer {4 :Beer_lead4, 8 :Beer_lead8})
;; Vector form with auto-named columns (:Beer_lead1, :Beer_lead2, etc.)
(add-leads ds :Beer [1 2 3 4])
;; Keep nils (don't drop rows)
(add-leads ds :Beer [1 2 3 4] {:drop-missing false})(add-time-columns ds time-col fields)Add columns extracted from a datetime column to a dataset.
time-col — keyword or string name of the source datetime column fields — vector of field keywords, or map of {field target-col-name}
Supported fields: Basic: :year, :month, :day, :hour, :minute, :second, :day-of-week, :day-of-year, :week-of-year, :quarter, :epoch-day, :epoch-week
Computed: :hour-fractional — decimal hour (e.g., 13.5 for 13:30) :daily-phase — position in day, 0→1 (0=midnight, 0.5=noon) :weekly-phase — position in week, 0→1 (0=Monday 00:00) :yearly-phase — position in year, 0→1 (0=Jan 1, ~0.5=July 1) :week-of-year-index — week within year (0-52), avoids ISO week boundary issues :date-string — date as "YYYY-MM-DD" string (for grouping) :year-string — year as string (for categorical color) :month-string — month as string (for categorical color) :week-string — week number as string (for categorical color) :day-of-week-string — day of week as string (for categorical color) :year-week-string — "YYYY-Www" format (for weekly seasonal grouping)
Examples: ;; vector form — column names match field names (add-time-columns ds :Month [:year :month]) ;; => adds :year and :month columns
;; map form — explicit output names (add-time-columns ds :Month {:year :Year, :month :MonthNum}) ;; => adds :Year and :MonthNum columns
;; computed fields for seasonal plots (add-time-columns ds :Time {:daily-phase "DailyPhase" :date-string "DateStr" :year-string "YearStr"})
Add columns extracted from a datetime column to a dataset.
time-col — keyword or string name of the source datetime column
fields — vector of field keywords, or map of {field target-col-name}
Supported fields:
Basic:
:year, :month, :day, :hour, :minute, :second,
:day-of-week, :day-of-year, :week-of-year, :quarter,
:epoch-day, :epoch-week
Computed:
:hour-fractional — decimal hour (e.g., 13.5 for 13:30)
:daily-phase — position in day, 0→1 (0=midnight, 0.5=noon)
:weekly-phase — position in week, 0→1 (0=Monday 00:00)
:yearly-phase — position in year, 0→1 (0=Jan 1, ~0.5=July 1)
:week-of-year-index — week within year (0-52), avoids ISO week boundary issues
:date-string — date as "YYYY-MM-DD" string (for grouping)
:year-string — year as string (for categorical color)
:month-string — month as string (for categorical color)
:week-string — week number as string (for categorical color)
:day-of-week-string — day of week as string (for categorical color)
:year-week-string — "YYYY-Www" format (for weekly seasonal grouping)
Examples:
;; vector form — column names match field names
(add-time-columns ds :Month [:year :month])
;; => adds :year and :month columns
;; map form — explicit output names
(add-time-columns ds :Month {:year :Year, :month :MonthNum})
;; => adds :Year and :MonthNum columns
;; computed fields for seasonal plots
(add-time-columns ds :Time {:daily-phase "DailyPhase"
:date-string "DateStr"
:year-string "YearStr"})Select rows from a dataset within a time range.
Usage: (slice ds :time-col start end) (slice ds :time-col start end {:sorted? true})
Arguments: ds — dataset time-col — name of the time column to slice on start — start time (inclusive), or nil for unbounded end — end time (inclusive), or nil for unbounded opts — optional map with :sorted? (skip sortedness check if true)
Examples: (slice ds :timestamp #time/date "2024-01-01" #time/date "2024-03-31") (slice ds :timestamp nil #time/date "2024-06-30") ; everything up to June (slice ds :timestamp #time/date "2024-07-01" nil) ; July onwards
Note: Data must be sorted by time-col. Use (tc/order-by ds :time-col) first if needed. Pass {:sorted? true} to skip the sortedness check for performance.
Select rows from a dataset within a time range.
Usage:
(slice ds :time-col start end)
(slice ds :time-col start end {:sorted? true})
Arguments:
ds — dataset
time-col — name of the time column to slice on
start — start time (inclusive), or nil for unbounded
end — end time (inclusive), or nil for unbounded
opts — optional map with :sorted? (skip sortedness check if true)
Examples:
(slice ds :timestamp #time/date "2024-01-01" #time/date "2024-03-31")
(slice ds :timestamp nil #time/date "2024-06-30") ; everything up to June
(slice ds :timestamp #time/date "2024-07-01" nil) ; July onwards
Note: Data must be sorted by time-col. Use (tc/order-by ds :time-col) first
if needed. Pass {:sorted? true} to skip the sortedness check for performance.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |