Skip to main content
added 44 characters in body
Source Link
MickyT
  • 3.4k
  • 16
  • 20

Without looking too deeply into what you are doing, returning the number of iterations is fairly straight forward. I have now made it so that infinite loops don't happen and made the threshold one of the function parameters.

hindex <- function(x, threshold){
iCounter <- 0 # Make counter 0
repeat{
    # does one of these have to be an ... equal to eg >= or <=?
    head <- x[x>mean(x)]
    tail <- x[x<mean(x)]
    headpct <- length(head)/sum(length(head),length(tail))
    if (headpct >.45 threshold) break # If head is > 45%threshold of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    x <- head # make x head for nextreset iterationX
    iCounter <- iCounter + 1 # Only increment if break doesn't occur
    }
return(iCounter) 
}

Without looking too deeply into what you are doing, returning the number of iterations is fairly straight forward

hindex <- function(x){
iCounter <- 0 # Make counter 0
repeat{
    # does one of these have to be an ... equal to eg >= or <=?
    head <- x[x>mean(x)]
    tail <- x[x<mean(x)]
    headpct <- length(head)/sum(length(head),length(tail))
    if (headpct >.45) break # If head is > 45% of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    x <- head # make x head for next iteration
    iCounter <- iCounter + 1 # Only increment if break doesn't occur
    }
return(iCounter) 
}

Without looking too deeply into what you are doing, returning the number of iterations is fairly straight forward. I have now made it so that infinite loops don't happen and made the threshold one of the function parameters.

hindex <- function(x, threshold){
iCounter <- 0 # Make counter 0
repeat{
    head <- x[x>mean(x)]
    tail <- x[x<mean(x)]
    headpct <- length(head)/sum(length(head),length(tail))
    if (headpct > threshold) break # If head is > threshold of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    x <- head # reset X
    iCounter <- iCounter + 1 # Only increment if break doesn't occur
    }
return(iCounter) 
}
added 125 characters in body
Source Link
MickyT
  • 3.4k
  • 16
  • 20

Without looking too deeply into what you are doing, returning the number of iterations is fairly straight forward

hindex <- function(x){
iCounter <- 0 # Make counter 0
repeat{
    # does one of these have to be an ... equal to eg >= or <=?
    head <- x[x>mean(x)]
    tail <- x[x<mean(x)]
    headpct <- length(head)/sum(length(head),length(tail))
    if (headpct >.45) break # If head is > 45% of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    x <- head # make x head for next iteration
    iCounter <- iCounter + 1 # Only increment if break doesn't occur
    }
return(iCounter) 
}

Without looking too deeply into what you are doing, returning the number of iterations is fairly straight forward

hindex <- function(x){
iCounter <- 0 # Make counter 0
repeat{
    head <- x[x>mean(x)]
    tail <- x[x<mean(x)]
    headpct <- length(head)/sum(length(head),length(tail))
    if (headpct >.45) break # If head is > 45% of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    iCounter <- iCounter + 1 # Only increment if break doesn't occur
    }
return(iCounter) 
}

Without looking too deeply into what you are doing, returning the number of iterations is fairly straight forward

hindex <- function(x){
iCounter <- 0 # Make counter 0
repeat{
    # does one of these have to be an ... equal to eg >= or <=?
    head <- x[x>mean(x)]
    tail <- x[x<mean(x)]
    headpct <- length(head)/sum(length(head),length(tail))
    if (headpct >.45) break # If head is > 45% of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    x <- head # make x head for next iteration
    iCounter <- iCounter + 1 # Only increment if break doesn't occur
    }
return(iCounter) 
}
Source Link
MickyT
  • 3.4k
  • 16
  • 20

Without looking too deeply into what you are doing, returning the number of iterations is fairly straight forward

hindex <- function(x){
iCounter <- 0 # Make counter 0
repeat{
    head <- x[x>mean(x)]
    tail <- x[x<mean(x)]
    headpct <- length(head)/sum(length(head),length(tail))
    if (headpct >.45) break # If head is > 45% of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    iCounter <- iCounter + 1 # Only increment if break doesn't occur
    }
return(iCounter) 
}