Table 1 I would like to collapse the rows so each timestamp is 1 row.
library(tidyverse)
table1 <- tribble(
~time, ~buoy, ~depth1, ~depth2, ~depth3,
"t1", "b1", NA, NA, "value",
"t1", "b1", NA, "value", NA,
"t1", "b1", "value", NA, NA,
"t2", "b1", NA, NA, "value",
"t2", "b1", NA, "value", NA,
"t2", "b1", "value", NA, NA
)
I currently have code to convert a long dataset with multiple parameters into a wide dataset with the timestamps as headers (see Table 2). I need the depths as headers and the time as rows in long format.
table2 <- tribble(
~depth, ~buoy, ~time1, ~time2, ~timen, ...,
"d1", "b1", "value", "value", "value", "v",
"d2", "b1", "value", "value", "value", "v",
"d3", "b1", "value", "value", "value", "v",
"d4", "b1", "value", "value", "value", "v",
"d2", "b1", "value", "value", "value", "v",
"t2", "b1", "value", "value", "value", "v"
)