-2

Guys I need your help on this issue. I currently have a table that contains information about future projections of professionals.

To be able to work better with this table I have to transform the columns of weeks into rows.

Table i Have

project Name   Local    09.12.2020 30.12.2020
1       Marie New York     20         0
1       John  New York     32        40
2       Marie New York     10         8
2       John  New York     8          0

The table I want ( I know I can do this in power bi with the function to transform lines over hills but I need it to be at R)

project Name   Local    Week          Hours
1       Marie New York  09.12.2020      30   
1       John  New York  09.12.2020      40   
2       Marie New York  30.12.2020      8    
2       John  New York  30.12.2020      40    

1 Answers1

2

You want pivot_longer() from the tidyr package.

library(tidyr)
library(dplyr)
data %>%
  pivot_longer(cols = -c(project, Name, Local), names_to = "Week", values_to = "Hours")
Ben Norris
  • 5,639
  • 2
  • 6
  • 15