I have a requirement to replace more than 2 continuous 1's with equal number of zeros. Currently, I can find the match as below but I don't know how to replace with the exact number of zeros as the match is found
ind<-c(1,1,0,0,0,1,1,1,1,0,1,1,0,0,0,1,1,0,1,0,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1,1,0)
gsub("([1])\\1\\1+","0",paste0(ind,collapse=""))
gives
"11000001100011010010101000101000"
as it replaces the match with just one 0 but I need
"11000000001100011010010101000000010100000"