Skip to content

[] for R

3 messages · kfcnhl, Vitalie S., Liviu Andronic

#
I am assuming the variable out is the output parameter.
However, I don't understand what is  out[1+xi*xx>0]?
Can someone explain this to me?

Thanks in advance,
Chen


dGEV <- function(x, xi, mu = 0, sigma = 1, logvalue=FALSE)
  {
    xx <- (x-mu)/sigma
    #use the new dGumbel which passes mu and sigma:
    #if (xi==0) out <- dGumbel(xx,logvalue=TRUE)-log(sigma)
    if (xi==0) {
       return(out <- dGumbel(x, mu, sigma, logvalue));
    }

    else
      { out <- rep(-Inf,length(x))
        out[1+xi*xx>0] <- (-1/xi-1)*log(1+xi*xx[1+xi*xx>0]) -
(1+xi*xx[1+xi*xx>0])^(-1/xi) -log(sigma)
      }
    if (!(logvalue))
      out <- exp(out)
    out
  }
#
see ?[

           For '['-indexing only: 'i, j, ...' can be logical vectors,
           indicating elements/slices to select.  Such vectors are
           recycled if necessary to match the corresponding extent.  'i,
           j, ...' can also be negative integers, indicating
           elements/slices to leave out of the selection.

so 1+xi*xx>0 is a logical vector.




On Mon, 24 Aug 2009 17:33:36 +0200, kfcnhl <zhengchenji18 at hotmail.com>  
wrote:
--