jeudi 3 décembre 2015

log of a matrix in R

I have a matrix whose elements contain zeros and close to zero elements and I want to get a matrix with the logarithm of each one of the elements, considering log0<-0 instead of Inf as it would give.

I tried:

takethelog <- function(A){
    if(A>0){
        return(logA)
    } else{
        return(logA <- 0)
    }
}

but it shows a warning:

In if (w > 0) { :
  the condition has length > 1 and only the first element will be used
> 

What should I do ?

Aucun commentaire:

Enregistrer un commentaire