Postgres: convert single row to multiple rows (unpivot)

A single SELECT with a LATERAL join to a VALUES expression does the job of “un-pivoting” columns to separate rows: SELECT p.id, v.* FROM price_list p CROSS JOIN LATERAL ( VALUES (‘type_a’, p.price_type_a) , (‘type_b’, p.price_type_b) , (‘type_c’, p.price_type_c) ) v (price_type, price); Related: Convert one row into multiple rows with fewer columns SELECT DISTINCT … Read more

R: Obtaining Rules from a Function

This isn’t my area of expertise, but perhaps this function (from https://www.togaware.com/datamining/survivor/Convert_Tree.html) will do what you want to do: library(rpart) car.test.frame$Reliability = as.factor(car.test.frame$Reliability) z.auto <- rpart(Reliability ~ ., car.test.frame) plot(z.auto, margin = 0.25) text(z.auto, pretty = TRUE, cex = 0.8, splits = TRUE, use.n = TRUE, all = FALSE) list.rules.rpart <- function(model) { if (!inherits(model, … Read more