# Create a pivot longer block
new_pivot_longer_block()
if (interactive()) {
# Basic usage with wide format data
library(blockr.core)
wide_data <- data.frame(
id = 1:3,
measurement_a = c(10, 20, 30),
measurement_b = c(15, 25, 35),
measurement_c = c(12, 22, 32)
)
serve(
new_pivot_longer_block(
cols = c("measurement_a", "measurement_b", "measurement_c"),
names_to = "measurement_type",
values_to = "value"
),
data = list(data = wide_data)
)
# With names_prefix to clean column names
serve(
new_pivot_longer_block(
cols = c("measurement_a", "measurement_b", "measurement_c"),
names_to = "type",
values_to = "measurement",
names_prefix = "measurement_"
),
data = list(data = wide_data)
)
}
Run the code above in your browser using DataLab