0

I'm working with R and my dataset looks like this :

Day Test1 Test2 Test 3
1 25 NA 30
2 NA 12 35
  • Code for the input dataframe:
df1 <- data.frame(Day = c(1,2),
                  Test1 = c(25,NA),
                  Test2 = c(NA,12),
                  Test3 = c(30, 35))

is there a way to change it to this structure :

Day Test Values
1 Test1 25
1 Test2 NA
1 Test3 30
2 Test1 NA
2 Test2 12
2 Test3 35
lovalery
  • 4,524
  • 3
  • 14
  • 28

1 Answers1

0
library(tidyverse)

df %>%
 pivot_longer(-Day, names_to = "Test", values_to = "Values")
denisafonin
  • 1,116
  • 1
  • 7
  • 16