Pivot Data to Long Format for Input and Output
pivot_longer_data.Rd
Transforms data from a wide format to a long format, creating separate rows
for total_input
and total_output
.
Value
A data frame in long format with a type
column indicating input or
output, and a value
column for the corresponding values.
Examples
# Example using a small sample data frame
power_data <- data.frame(
timestamp = c(
as.POSIXct("2000-01-01 01:00:00", tz = "UTC"),
as.POSIXct("2000-01-02 01:00:00", tz = "UTC"),
as.POSIXct("2000-02-01 02:00:00", tz = "UTC"),
as.POSIXct("2000-02-02 02:00:00", tz = "UTC")
),
total_input = c(1.0, 2.0, 3.0, 4.0),
total_output = c(4.0, 3.0, 2.0, 1.0)
)
pivot_longer_data(power_data)
#> # A tibble: 8 × 3
#> timestamp type value
#> <dttm> <chr> <dbl>
#> 1 2000-01-01 01:00:00 total_input 1
#> 2 2000-01-01 01:00:00 total_output 4
#> 3 2000-01-02 01:00:00 total_input 2
#> 4 2000-01-02 01:00:00 total_output 3
#> 5 2000-02-01 02:00:00 total_input 3
#> 6 2000-02-01 02:00:00 total_output 2
#> 7 2000-02-02 02:00:00 total_input 4
#> 8 2000-02-02 02:00:00 total_output 1