Pivots a kinematics dataset into long format
Source:R/pivot_kinematics.R
pivot_kinematics_longer.RdConverts a wide-format data frame where each point's variables are separate
columns (e.g. head.x, head.y, tail.x, tail.y) into a long format
with one row per point per frame. The point column is returned as a factor
with levels in the order given by pointnames.
Examples
df <- data.frame(
frame = 1:3,
head.x = c(0, 0, 0), head.y = c(0, 1, 2),
tail.x = c(5, 5, 5), tail.y = c(0, 1, 2)
)
pivot_kinematics_longer(df, c("head", "tail"))
#> # A tibble: 6 × 4
#> frame point x y
#> <int> <fct> <dbl> <dbl>
#> 1 1 head 0 0
#> 2 1 tail 5 0
#> 3 2 head 0 1
#> 4 2 tail 5 1
#> 5 3 head 0 2
#> 6 3 tail 5 2