Hello,

I would like to take advantage of the upper.tri() function here but I don't
know exactly. Here is some working code...
i<-5
fi<-matrix(0,nrow=i,ncol=i)
for(r in 1:i){
for(c in 1:i){
if(r==c){
 fi[r,c]<-1
}else if(r<c){
fi[r,c]<-1-runif(1)^.5
 }else{
fi[r,c]<-fi[c,r]
}
 }
}

So far I know I can simplify this code to 5 lines (no for loops):
i<-5
fi<-matrix(nrow=i,ncol=i)
fi[upper.tri(fi)]<-1-runif(length(fi[upper.tri(fi)]))^.5
diag(fi)<-1
fi[lower.tri(fi)]<-fi[upper.tri(fi)]#This entry is not correct. fi[r,c] ! ==
fi[c,r]

Any suggestions?

Sincerely,
Brian

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to