-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeomMean.R
More file actions
56 lines (30 loc) · 1.1 KB
/
Copy pathGeomMean.R
File metadata and controls
56 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
## GeomMean.R ##
#' @export
#'
##############################################
## Author Information ##
# * Author: E.Frolli
# * Orginization: Univeristy of Texas Marine Science Institute
# * Contact: frolli.erin@utexas.edu
# * Date: 23 Jun 2017
##############################################
## The Code ##
GeomMean <- function (x){
##############################################################
# Warnings - make sure that they have all the corect values
##############################################################
# No non-negative values
if (any(x < 0)) {
stop("'x' contains negative value(s)")
}
# No NA values
if (any(is.na(x))) {
stop("'x' contains NA values")
}
##############################################################
# Main Function
##############################################################
GometricMean = round(prod(x)^(1/length(x)),digits = 4) # Comput the Geometric mean rounded to the 2 decimal place
# return Data
return(GometricMean)
}