I've got a list of numbers [2554, 201, 452, 3111, 4133, 2210, 1235, 430, 4210, 11, 513, 1305, 2550, 5312, 512, 3535, 1014, 4013, 234, 4112, 13, 2433, 5233, 4500]. I'm trying to found out have many of these numbers contain consecutive digits. For example 2554 has consecutive digits (5) but 513 and 3535 do not. I know the total amount of numbers with consecutive digits is 10 out of 24.
#my code
count = 0
z = c(2554, 201, 452, 3111, 4133, 2210, 1235, 430, 4210, 11, 513, 1305, 2550, 5312, 512, 3535, 1014, 4013, 234, 4112, 13, 2433, 5233, 4500)
for(i in 1:24){
if((grep(pattern = "\\d{2}", x = z[i])) == 1){
count = count + 1
}
}
I'm trying to use grep but it's not working, is there anything I'm doing wrong?