Revision 128cc5eed366a5a3f6c33b70a81379c1b1ca8688 authored by Matthias Templ on 16 August 2010, 18:42:55 UTC, committed by cran-robot on 16 August 2010, 18:42:55 UTC
1 parent 4c9961a
Raw File
clr.R
clr <- function(x){
	#if(dim(x)[2] < 2) stop("data must be of dimension greater equal 2")
	if(dim(x)[2] == 1){
		res <- list(x.clr=x, gm=rep(1,dim(x)[1]))	    	
	} else{
	geometricmean <- function (x) {
		if (any(na.omit(x == 0)))
			0
		else exp(mean(log(unclass(x)[is.finite(x) & x > 0])))
	}
	gm <- apply(x, 1, geometricmean)
	x.clr <- log(x/gm)
	res <- list(x.clr=x.clr, 
			    gm=gm
		   )
	}
	class(res) <- "clr"
	invisible(res)  
}
back to top