Stemming off of:
- "don't want the NA values", and
- "rows 1-3 combined into 1 and so on"
Perhaps this will work:
dat <- data.frame(id=1:6, T=c("2009-06-11",NA,NA,"2009-06-11",NA,NA), U=c(NA,"https://www1",NA,NA,"https://www2",NA),W=c(NA,NA,"post1",NA,NA,"post2"))
dat
# id T U W
# 1 1 2009-06-11 <NA> <NA>
# 2 2 <NA> https://www1 <NA>
# 3 3 <NA> <NA> post1
# 4 4 2009-06-11 <NA> <NA>
# 5 5 <NA> https://www2 <NA>
# 6 6 <NA> <NA> post2
by(
dat, cumsum(!is.na(dat$T)),
function(Z) data.frame(lapply(Z[-1], function(x) paste(na.omit(x), collapse=";")[1]))
) |>
do.call(rbind, args = _)
# T U W
# 1 2009-06-11 https://www1 post1
# 2 2009-06-11 https://www2 post2
(|>
and _
requires R >= 4.2.0, this can be made to work with older R without difficulty.)