This is certainly not pretty, but it works:
do.call(cbind, lapply(1:ceiling(ncol(df)/4), function(i)
apply(df[,seq(4*(i-1)+1, min(4*i, ncol(df))), drop = F],
1, paste, collapse = "/")))
# [,1] [,2]
#ind.1 "257/262/228/266" "204/245/282/132"
#ind.2 "244/115/240/187" "196/133/189/251"
#ind.3 "298/139/216/225" "219/276/192/254"
#ind.4 "129/176/180/182" "215/250/227/186"
#ind.5 "238/217/284/240" "131/184/247/168"
The ceiling
and drop
are there to survive edge cases when number of columns is not divisible by 4. Also, note that the end result is a matrix
here (thanks to the apply
), and you can convert it back to data.frame
if you like (and assign whatever column names).