R implementation of function

If your column name is stored in a variable (in your case a parameter), x$y will not work as is (at least not to my knowledge). What you can do is use x[, y] to retrieve the right column. Note that you should use a string (so "SALES", not SALES):

calculate.d <- function(x, y, p) {
  column <- x[, y]
  m <- mean(column)
  s <- sd(column)
  d <- qnorm(1-p,mean=m,sd=s)-m

#notice that "SALES" is a string here
calculate.d(df, "SALES", 0.1)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top