Advertisement
Guest User

Untitled

a guest
Jun 9th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.32 KB | None | 0 0
  1. get_tau<-function(cp.table){
  2.   N <- nrow(cp.table);
  3.   iseq <- 1:N;
  4.   tau<-apply(as.matrix(iseq), 2,
  5.              function (i,j) {
  6.                  sqrt((cp.table$x[i] - cp.table$x[j])^2 + (cp.table$y[i] - cp.table$y[j])^2)
  7.              },
  8.              j=1);
  9.  
  10.    for(j in 2:N) {
  11.        tau <- cbind(tau,
  12.                     apply(as.matrix(iseq), 2,
  13.                           function(i,j) {
  14.                               sqrt((cp.table$x[i]-cp.table$x[j])^2 + (cp.table$y[i]-cp.table$y[j])^2)
  15.                           },
  16.                           j)
  17.                    )
  18.    };
  19.    return (tau);
  20. }
  21.  
  22.  
  23. get_tau2<-function(cp.table){
  24.   N <- nrow(cp.table);
  25.   g <- as.matrix(expand.grid(1:N, 1:N))
  26.  
  27.   tau<-apply(as.matrix(g), 1,
  28.              function (index) {
  29.                  sqrt((cp.table$x[index[1]] - cp.table$x[index[2]])^2 +
  30.                       (cp.table$y[index[1]] - cp.table$y[index[2]])^2)
  31.              }
  32.              );
  33.  
  34.   return (matrix(tau, nrow=N));
  35. };
  36.  
  37. get_tau3<-function(cp.table){
  38.   N <- nrow(cp.table);
  39.   iseq <- 1:N;
  40.   sapply(as.list(iseq),
  41.         function(j) {
  42.           f.int <- function (i, j) {
  43.               return(sqrt((cp.table$x[i] - cp.table$x[j])^2 + (cp.table$y[i] - cp.table$y[j])^2))
  44.           }
  45.  
  46.           return (apply(as.matrix(iseq), 2, f.int, j))
  47.         }
  48.       )
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement