Reshape functions for datajure. Currently provides wide->long (melt).
Reshape functions for datajure. Currently provides wide->long (melt).
(melt dataset
{:keys [id measure variable-col value-col]
:or {variable-col :variable value-col :value}})Reshape a dataset from wide to long format.
Arguments: dataset - a tech.v3.dataset opts - map with keys: :id - (required) vector of column keywords to keep as identifiers :measure - vector of column keywords to stack. Defaults to all non-id columns. :variable-col - keyword for the new variable column. Defaults to :variable. :value-col - keyword for the new value column. Defaults to :value.
Returns a dataset with one row per (id, measure) combination. If no measure columns exist (all columns are id columns), returns an empty dataset with the id columns plus the variable and value columns.
Examples: ;; Basic melt (melt ds {:id [:species :year] :measure [:mass :flipper :bill]})
;; Infer measure cols (all non-id) (melt ds {:id [:species :year]})
;; Custom output column names (melt ds {:id [:species :year] :measure [:mass :flipper] :variable-col :metric :value-col :val})
Reshape a dataset from wide to long format.
Arguments:
dataset - a tech.v3.dataset
opts - map with keys:
:id - (required) vector of column keywords to keep as identifiers
:measure - vector of column keywords to stack. Defaults to all non-id columns.
:variable-col - keyword for the new variable column. Defaults to :variable.
:value-col - keyword for the new value column. Defaults to :value.
Returns a dataset with one row per (id, measure) combination.
If no measure columns exist (all columns are id columns), returns an empty dataset
with the id columns plus the variable and value columns.
Examples:
;; Basic melt
(melt ds {:id [:species :year] :measure [:mass :flipper :bill]})
;; Infer measure cols (all non-id)
(melt ds {:id [:species :year]})
;; Custom output column names
(melt ds {:id [:species :year] :measure [:mass :flipper]
:variable-col :metric :value-col :val})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 |