0

I have the dataframe below:

Unp<-structure(list(Week = structure(c(17903, 17910, 17917, 17924, 
17931, 17938, 17945, 17952, 17959, 17966, 17973, 17980, 17987, 
17994, 18001, 18008, 18015, 18022, 18029, 18036), class = "Date"), 
    Target = c(5, 8, 15, 20, 25, 25, 25, 25, 25, 25, 25, 25, 
    25, 25, 25, 25, 25, 25, 25, 25), `Cumilative target` = c(5, 
    13, 28, 48, 73, 98, 123, 148, 173, 198, 223, 248, 273, 298, 
    323, 348, 373, 398, 423, 448)), row.names = c(NA, -20L), class = c("tbl_df", 
"tbl", "data.frame")) 

Week       Target `Cumilative target`
   <date>      <dbl>               <dbl>
 1 2019-01-07      5                   5
 2 2019-01-14      8                  13
 3 2019-01-21     15                  28
 4 2019-01-28     20                  48
 5 2019-02-04     25                  73

and I want to proceess it in a way that a Type column will show whether is Target or Cumulative target. So it will include the 2 previous column names and a third column named Count which will include the values of the previous 2 column names like:

 Week            Type Count
1 2019-01-07            Target     5
2 2019-01-07 Cumulative target     5
firmo23
  • 7,490
  • 2
  • 38
  • 114

1 Answers1

1

We just need to pivot to long

library(tidyr)
pivot_longer(Unp, cols = -Week, names_to = "Type", values_to = "Count")
akrun
  • 874,273
  • 37
  • 540
  • 662