neighbor2<-function(x){ #function to make all 2-neighbors #x is the input string out.file<-x #holds result #First change: 1-neighborhood specification for(j in 1:6){ for(k in 1:4){ y<-x if(k!=x[j]){ y[j]<-k #Second change: becomes 2-neighborhood specification for(m in 1:6){ if(m!=j){ for(n in 1:4){ z<-y if(n!=x[m]){ z[m]<-n out.file<-rbind(out.file,z) }}}} }}} out.file<-out.file[2:length(out.file[,1]),] return(out.file) #contains sequence variants with two changes }