I wanted to use function pivot_longer() and pivot_wider() for iris dataset. This is the code to lengthen the data:
iris_ds <- iris %>% pivot_longer(-Species, names_to = "Measure", values_to = "Value")
In the documentation it says that pivot_wider() is the inverse transformation of pivot_longer(), so I apply the code:
iris_or <- iris_ds %>% pivot_wider(names_from = "Measure", values_from = "Value")
and I get the following table:
Species Sepal.Length Sepal.Width Petal.Length Petal.Width
setosa <dbl> <dbl> <dbl> <dbl>
versicolor <dbl> <dbl> <dbl> <dbl>
virginica <dbl> <dbl> <dbl> <dbl>
This was answered in the gather() spread() similar question (using a RowId was suggested), the help I want is if the new functions pivot_longer and pivot_wider have a way to manage this to make it transitive. Thank you in advance for your answers.