aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--R/geometric_mean.R4
-rw-r--r--man/geometric_mean.Rd23
3 files changed, 29 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index f80bc132..0dab3199 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
2014-06-26 Johannes Ranke <jranke@uni-bremen.de> for mkin (0.9-29)
* R/mkinresplot.R: Make it possible to specify xlim
+ * R/geometric_mean.R, man/geometric_mean.Rd: Add geometric mean
+ function
2014-05-20 Johannes Ranke <jranke@uni-bremen.de> for mkin (0.9-28)
diff --git a/R/geometric_mean.R b/R/geometric_mean.R
new file mode 100644
index 00000000..646732cd
--- /dev/null
+++ b/R/geometric_mean.R
@@ -0,0 +1,4 @@
+geometric_mean <- function(x, na.rm = FALSE)
+{
+ exp(mean(log(x), na.rm = na.rm))
+}
diff --git a/man/geometric_mean.Rd b/man/geometric_mean.Rd
new file mode 100644
index 00000000..faad666f
--- /dev/null
+++ b/man/geometric_mean.Rd
@@ -0,0 +1,23 @@
+\name{geometric_mean}
+\Rdversion{1.1}
+\alias{geometric_mean}
+\title{ Calculate the geometric mean }
+\description{
+ Function calculating the geometric mean of numeric vectors
+}
+\usage{
+ geometric_mean(x, na.rm = FALSE)
+}
+\arguments{
+ \item{x}{ A numeric vector }
+ \item{na.rm}{ Should NA values be ignored }
+}
+\value{
+ The geometric mean.
+}
+\examples{
+ geometric_mean(c(1,3, 9))
+ geometric_mean(c(1,3, NA))
+ geometric_mean(c(1,3, NA), na.rm = TRUE)
+}
+\keyword{ manip }

Contact - Imprint