I recreated a dummy dataset that matches the data structure you provided. In the future, use the suggestions @r2evans gave for providing reproducible data. That will make answering your question much easier.
For reference, look up tidyr and gather. This is used to convert data from wide (your data) to long (the data structure you want).
Package used:
library(tidyverse)
Example of your data:
data <- data.frame("WPT1" = sample(1:100,10),
"WPT2" = sample(1:100,10),
"WPT3" = sample(1:100,10),
"WPT4" = sample(1:100,10),
"dt" = sample(seq(as.Date('1999/01/01'),
as.Date('2000/01/01'), by="day"), 10)
)
head(data)[1:5]
WPT1 WPT2 WPT3 WPT4 dt
1 33 49 79 85 1999-06-30
2 62 13 75 45 1999-07-16
3 96 86 60 34 1999-03-10
4 4 21 66 64 1999-08-18
5 49 70 32 49 1999-09-04
Conversion to long format:
data.long <- data %>%
gather(ID,WP,-dt) %>%
mutate(ID = replace(ID,ID == "WPT1",1),
ID = replace(ID,ID == "WPT2",2),
ID = replace(ID,ID == "WPT3",3),
ID = replace(ID,ID == "WPT4",4),
ID = as.numeric(ID)
)
Output:
head(data.long)[1:5,]
dt ID WP
1 1999-06-30 1 33
2 1999-07-16 1 62
3 1999-03-10 1 96
4 1999-08-18 1 4
5 1999-09-04 1 49