0

I have a dataset that has multiple columns, each column represent a different value of the ID. I would like to convert these value rows into a single column.

Sample data

ID             Elevation_1       Elevation_2      Elevation_3     Elevation_4
 279557         2070.934         2457.829         2954.444            0.000
 280485         2070.934         2457.829         2966.311         3226.203
 

Desired output

ID      Elevation
279557  2070.934
279557  2457.829 
279557  2954.444 
279557  0.000
280485  2070.934         
280485  2457.829  
280485  2966.311 
280485  3226.203     

What I have tried so far

library(tidyverse)
library(dplyr)

df = df%>% 
  gather(ID)

I also oooked into pivot_longer but couldn't quite understand how to use it in this case.

How can this be done using dplyr?

Ed_Gravy
  • 1,841
  • 2
  • 11
  • 34

0 Answers0