###################################################################### posMinV1 <- function(vect) { ###################################################################### # lent : on part d'un vecteur vide et on lui ajoute chaque position vue du minimum if (missing(vect)) { cat("\nSyntax: posMinV1(vect).\n") } else { pdm <- c() # c() est la notation pour le vecteur vide nbe <- length(vect) vm <- min(vect) # valeur du Minimum for (ide in 1:nbe) { # pour debug : cat(" ide ",sprintf("%3d",ide)," x = ",vect[ide]," donc pdm " , pdm,"\n") if (vect[ide]==vm) { pdm <- c(pdm,ide) } } # fin pour ide return(pdm) } # fin si } # fin de fonction posMinV1 ###################################################################### posMinV2 <- function(vect) { ###################################################################### # rapide ? on utilise la comparaison vectorielle avec == if (missing(vect)) { cat("\nSyntax: posMinV2(vect).\n") } else { return( (1:length(vect))[vect==min(vect)] ) } # fin si } # fin de fonction posMinV2 ###################################################################### posMinV3 <- function(vect) { ###################################################################### # sans doute aussi rapide que posMinV2 mais plus lisible if (missing(vect)) { cat("\nSyntax: posMinV3(vect).\n") } else { pdv <- 1:length(vect) # plage de variation des indices flt <- vect==min(vect) # filtre pdm <- pdv[ flt ] return(pdm) } # fin si } # fin de fonction posMinV3 ###################################################################### posMinV4 <- function(vect) { ###################################################################### # sans doute aussi rapide que posMinV2 mais plus lisible if (missing(vect)) { cat("\nSyntax: posMinV4(vect).\n") } else { pdv <- 1:length(vect) # plage de variation des indices vmi <- min(vect) # valeur du min flt <- vect==vmi # filtre pdm <- pdv[ flt ] return(pdm) } # fin si } # fin de fonction posMinV4 ###################################################################### posMinV5 <- function(vect) { ###################################################################### # on utilise which if (missing(vect)) { cat("\nSyntax: posMinV5(vect).\n") } else { return( which(vect==min(vect)) ) } # fin si } # fin de fonction posMinV5 ###################################################################### posMinV6 <- function(vect) { ###################################################################### # on utilise which et on sort min(vect) du test if (missing(vect)) { cat("\nSyntax: posMinV6(vect).\n") } else { vmi <- min(vect) # valeur du min return( which(vect==vmi) ) } # fin si } # fin de fonction posMinV6