# --- Wide to long ---
# Columns named as prices (auto-parsed)
wide_num <- data.frame(
id = 1:3,
"0" = c(10, 8, 12), "0.5" = c(9, 7, 11), "1" = c(8, 6, 9),
check.names = FALSE
)
pivot_demand_data(wide_num, format = "long")
# Columns with non-numeric names require x_values
wide_named <- data.frame(id = 1:2, price_1 = c(10, 8), price_2 = c(5, 4))
pivot_demand_data(wide_named, format = "long",
x_values = c(0, 0.5))
# --- Long to wide ---
data(apt, package = "beezdemand")
wide_apt <- pivot_demand_data(apt, format = "wide")
head(wide_apt)
Run the code above in your browser using DataLab