0

I have this type of database in an Excel file

Date     UGA1   UGA2   UGA3  UGA4    UGA5  
01/2018  54      12     78     45      78
02/2018  75      5      74     8       45
03/2018  2       6      65     65      45
04/2018  87      15     8      74      47
05/2018  8       64     1      14      6
06/2018  9       57     2      24      78

And I would like to get this type of table by using R code

  UGA      Date     Value
  UGA1    01/2018   54
  UGA1    02/2018   75
  UGA1    03/2018   2
  UGA2    01/2018   12
  UGA2    02/2018   5
  UGA2    03/2018   6

I have no idea how to do this

For the moment I've only read my excel file by using this command

am = read_excel("C:/Users/david/OneDrive/Bureau/Master data/Mémoire data analyst/Bases de 
données/Ventes/AM_per_UGA.xlsx")

I would like to have my rearrange database stored in a new variable

Than you in advance for your help

user438383
  • 5,716
  • 8
  • 28
  • 43
Antoine
  • 29
  • 2
  • 3
    You want to [reshape data.frame from wide to long format](https://stackoverflow.com/questions/2185252/reshaping-data-frame-from-wide-to-long-format) – harre Jul 22 '22 at 09:57
  • A possible solution: `df %>% pivot_longer(-1, names_to = "UGA") %>% arrange(UGA) %>% relocate(Date, .after = "UGA")` – PaulS Jul 22 '22 at 09:59
  • 1
    Please don't use the Rstudio tag unless your question specifically relates to Rstudio. – user438383 Jul 22 '22 at 09:59

0 Answers0