ifname<-"Datalong.csv"
longdata<-read.delim(ifname,row.names=2,header=T,sep=",",as.is=TRUE) 
dataUsed<-longdata[,-c(1)]; dim(dataUsed)
#[1]--------
cordata<-cor(dataUsed, use = "na.or.complete",method = c("pearson"))
#--------
dataN<-colnames(dataUsed)
nf<-dim(dataUsed)[[2]]
ns<-dim(dataUsed)[[1]]
ndata<-matrix(rep(0,times=(nf*nf)), nrow=nf, ncol=nf)
cdata<-matrix(rep(0,times=(nf*nf)), nrow=nf, ncol=nf)
named<-matrix(rep("",times=(nf*nf)), nrow=nf, ncol=nf)
#[2]---------
for(s in 1:nf){
  for(t in 1:nf){
    ndata[s,t]<-sum(dataUsed[,s]!="NA"&dataUsed[,t]!="NA",na.rm=TRUE)
    cdata[s,t]<-cor(dataUsed[,s],dataUsed[,t], use = "na.or.complete",method = c("pearson"))
    named[s,t]<-paste(dataN[s],dataN[t],sep=",")
  }
}
nuesankaku<-ndata[upper.tri(ndata,diag=FALSE)]
cuesankaku<-cdata[upper.tri(ndata,diag=FALSE)]
nameuesankaku<-named[upper.tri(named,diag=FALSE)]
#[3]-----
hist(nuesankaku,xlim=c(1,ns),breaks=ns,main="Number of paired samples")
hist(cuesankaku,xlim=c(-1,1),breaks=200,main="Pearson correlation")
#[4]-----
mm<-unlist(strsplit(nameuesankaku , ","))
namepairs<-matrix(mm,nrow=nf*(nf-1)/2,ncol=2,byrow=T)
dd<-data.frame(namepairs,cuesankaku)
sdata<-dd[order(dd[,3],decreasing = TRUE),]
colnames(sdata)<-c("Var1","Var2","correl")
write.csv(sdata,file="DataCorrelRank.csv",row.names =FALSE)