aboutsummaryrefslogtreecommitdiff
path: root/pkg/R/geomean.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2016-09-27 23:00:48 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2016-09-27 23:00:48 +0200
commit12a31f4c130c551f82232d9ef7dfb608bd52c53f (patch)
tree2525ab1ea4102a6edddbd0c2f03f4a851bf2f9c5 /pkg/R/geomean.R
parent0d958ab6f84b569b5437f231c56004890c4ae23b (diff)
Reorganise repository using standard package layout
Diffstat (limited to 'pkg/R/geomean.R')
-rw-r--r--pkg/R/geomean.R38
1 files changed, 0 insertions, 38 deletions
diff --git a/pkg/R/geomean.R b/pkg/R/geomean.R
deleted file mode 100644
index 626829b..0000000
--- a/pkg/R/geomean.R
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (C) 2015 Johannes Ranke
-# Contact: jranke@uni-bremen.de
-# This file is part of the R package pfm
-
-# This program is free software: you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by the Free Software
-# Foundation, either version 3 of the License, or (at your option) any later
-# version.
-
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-# details.
-
-# You should have received a copy of the GNU General Public License along with
-# this program. If not, see <http://www.gnu.org/licenses/>
-
-#' Calculate the geometric mean
-#'
-#' Based on some posts in a thread on Stackoverflow
-#' \url{http://stackoverflow.com/questions/2602583/geometric-mean-is-there-a-built-in}
-#' This function checks for negative values, removes NA values per default and
-#' returns 0 if at least one element of the vector is 0.
-#'
-#' @param x Vector of numbers
-#' @param na.rm Should NA values be omitted?
-#' @return The geometric mean
-#' @export
-#' @author Johannes Ranke
-#' @examples
-#' geomean(c(1, 3, 9))
-#' geomean(c(1, 3, NA, 9))
-#' \dontrun{geomean(c(1, -3, 9)) # returns an error}
-geomean = function(x, na.rm = TRUE){
- if (any(is.na(x)) & na.rm == FALSE) stop("Removal of NA values was not requested")
- if (any(x < 0, na.rm = na.rm)) stop("Only defined for positive numbers")
- exp(mean(log(x), na.rm = na.rm))
-}

Contact - Imprint