HI, Try this:
dat1<- read.csv("DQP.csv",sep="\t") res<- do.call(cbind,lapply(seq_len(nrow(dat1)),function(i) do.call(rbind,lapply(split(rbind(dat1[i,],dat1[-i,]),1:nrow(rbind(dat1[i,],dat1[-i,]))), function(x) {x1<-rbind(dat1[i,],x);colnames(x1)<-gsub("[.]","",colnames(x1)); if({indx<- colSums(x1[,2:3]==0);indx[1]==0 & indx[2]==1 }) #2 peaks 1 peak comparison {x2<- x1[order(x1$Peak2t,x1$Npeak2t),]; with(x2,{abs((Peak1v[1]-Peak1v[2])*(Peak1t[1]-Peak1t[2]))+abs((Peak1v[1]-Peak2v[2])*((Peak1t[1]+12)-Peak2t[2]))+ abs((Npeak1v[1]-Npeak1v[2])*(Npeak1t[1]-Npeak1t[2]))+abs((Npeak1v[1]-Npeak2v[2])*((Npeak1t[1]+12)-Npeak2t[2])) }) } else #cases where peaks are similar {with(x1,{abs((Peak1v[1]-Peak1v[2])*(Peak1t[1]-Peak1t[2]))+abs((Peak2v[1]-Peak2v[2])*(Peak2t[1]-Peak2t[2])) + abs((Npeak1v[1]-Npeak1v[2])*(Npeak1t[1]-Npeak1t[2]))+abs((Npeak2v[1]-Npeak2v[2])*(Npeak2t[1]-Npeak2t[2]))}) } })))) res2<-do.call(cbind,lapply(seq_len(ncol(res)),function(i) c(c(tail(res[seq(1,i,1),i],-1),0),res[-c(1:i),i]))) row.names(res2)<-1:nrow(res2) dim(res2) #[1] 124 124 res2[1:5,1:5] # [,1] [,2] [,3] [,4] [,5] #1 0.000 1.512 7.031 3.662 13.030 #2 1.512 0.000 7.109 4.880 18.731 #3 7.031 7.109 0.000 0.056 1.280 #4 3.662 4.880 0.056 0.000 0.584 #5 13.030 18.731 1.280 0.584 0.000 A.K. ________________________________ From: eliza botto <eliza_bo...@hotmail.com> To: "smartpink...@yahoo.com" <smartpink...@yahoo.com> Sent: Wednesday, March 27, 2013 8:58 AM Subject: RE: Distance calculation Dear Arun, I would like to ask a small question. In the distance calculation procedure, if there are only 2 peaks and 1 peaks stations and there are no 3 and 4 peaks stations, like the file i attached. How to modify the script below to eliminate 3 peaks and 4 peaks scripts?? I hope you mind my hasty questioning Thanks in advance Elisa ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.