### Exercise box pairing unpairing - two approaches # preliminaries - get list of bases that are pairing and which unpairing types<-"PPPPPUUUUPPPPPPPUPPUUUPPPPUUUUUUUUUUPPPPPPUUUUU" U<-which(unlist(strsplit(types,""))=="U") P<-which(unlist(strsplit(types,""))=="P") Pgroups<-split(P, cumsum(c(1, diff(P) != 1))) Ugroups<-split(U, cumsum(c(1, diff(U) != 1))) # Simple answer temp<-NULL for(i in 1:length(Pgroups)){ temp<-c(temp,paste(range(Pgroups[i]),collapse="-")) } pairing<-paste(temp,collapse=", ") pairing #[1] "1-5, 10-16, 18-19, 23-26, 37-42" temp<-NULL for(i in 1:length(Ugroups)){ temp<-c(temp,paste(range(Ugroups[i]),collapse="-")) } unpairing<-paste(temp,collapse=", ") unpairing #[1] "6-9, 17-17, 20-22, 27-36, 43-47"