Julia equivalent of R's quantile function

Sandy45
Tue, 08 Aug 2023 02:59:27 +0000
Performance

I am trying to convert R code to Julia and need help on below logic conversion.

Currently in R they are trying to process each row in percentile_to df using for loop by passing arguments to function func_get_percentile_value.

I know we can do this easily using transform in julia but question here is in the func_get_percentile_value function they are doing quantile based on another df() matched values.

Ex: quantile(history[IN_GR == type, ACT_TIN_MINUTES], probs = prob

I would like to check if we can pass another df in the transform function? or best way to handle this scenario?

I would also like to check on quantile function, I saw there is quantile function in Distributions module, need confirmation if I can use this also how about probs that is being used in R.

for(i in 1:nrow(percentile_to.dt)){
      row = percentile_to.dt[i,]
      percentile_to.dt[i,"TO_MAX"] <- func_get_percentile_value("ABC", "TO", row$depart, row$arrival, row$TO_Percentile_Threshold)
      percentile_to.dt[i,"TO_REPLACE"] <- func_get_percentile_value("ABC", "TO", row$depart, row$arrival, row$TO_Percentile_Replace)
    }

func_get_percentile_value <- function(type, mode, origin, destination, percentile){
  if (!is.numeric(percentile) | percentile<0 | percentile>100){
    return(NULL)
  } else{
    prob = percentile/100
  }

  if (origin == "*" & destination == "*"){
    if (mode == "TO"){
      return(quantile(history[OUT_GR == type, ACT_OUT_MINUTES], probs = prob))
    } else if (mode == "TI"){
      return(quantile(history[IN_GR == type, ACT_TIN_MINUTES], probs = prob))
    }
  }
}

8 posts - 4 participants