[R] Slow function

Marc marc.moragues at gmail.com
Tue Jun 10 10:49:23 CEST 2008


Hi,

I have the following function that I want to apply to a list of 14 
matrices (1536 x 170) of binary data:

DRes <- function(x, nr = 10000, metric = "mixed", ...) {
  require(analogue)
  require(ade4)
  m <- c()
  for (i in 1:nr) {
    set.seed(i)
    x1 <- x[, sample(dimnames(x)[[2]], length(x[1,])/2)]
    x2 <- x[, !dimnames(x)[[2]] %in% dimnames(x1)[[2]]]
    d1 <- as.dist(distance(as.data.frame(x1), method = metric))
    d2 <- as.dist(distance(as.data.frame(x2), method = metric))
    m[i] <- mantel.rtest(d1, d2, ...)$obs
    mean <- mean(m)
    std <- sd(m)
    res <- list(mean = mean, std = std)
  }
  return(res)
}
bias.dres <- sapply(bias, DRes)

I run this code and after 3 hours is still running. I am on Windows XP 
and this is my sessionInfo()
 > sessionInfo()
R version 2.7.0 Patched (2008-05-02 r45580)
i386-pc-mingw32

locale:
LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United 
Kingdom.1252;LC_MONETARY=English_United 
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] analogue_0.5-1 vegan_1.11-4   ade4_1.4-7 

Any help will be very much appreciated.
Marc.



More information about the R-help mailing list