x = c(0,2,6,1,0,0,0,5,4,0,0,3,3,0,0,2,0,0,7,1,4,0,7,0,5,6,0,0,0)
xt = x
# replace lone non-0s with 0
xt[which(lag(x) == 0 & lead(x) == 0)] = 0
# use RLE, ignoring the first element
with(rle(xt == 0), lengths[c(-1, -length(lengths))][values[c(-1, -length(lengths))]]) + 1
# [1] 4 3 6 4