My dataset currently looks something like this:
id date00 var1_00 var2_00 date01 var1_01 var2_01
1 1/1/2019 1 2 1/1/2020 3 4
2 2/2/2019 1 2 2/2/2020 3 4
3 3/3/2019 1 2 3/3/2020 3 4
The code for the table:
structure(list(id = c(1, 2, 3), date00 = structure(c(1546300800,
1549065600, 1551571200), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
var1_00 = c(1, 1, 1), var2_00 = c(2, 2, 2), date01 = structure(c(1577836800,
1580601600, 1583193600), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
var1_01 = c(3, 3, 3), var2_01 = c(4, 4, 4)), row.names = c(NA,
-3L), class = c("tbl_df", "tbl", "data.frame"))
How can I reshape it so it looks like this:
id date var1_00 var2_00 var1_01 var2_01
1 1/1/2019 1 2 NA NA
2 2/2/2019 1 2 NA NA
3 3/3/2019 1 2 NA NA
1 1/1/2020 NA NA 3 4
2 1/1/2020 NA NA 3 4
3 1/1/2020 NA NA 3 4
Thank you!
question from:
https://stackoverflow.com/questions/65601619/need-help-reshaping-an-r-dataset 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…