-
Notifications
You must be signed in to change notification settings - Fork 0
/
availability.R
31 lines (26 loc) · 961 Bytes
/
availability.R
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
#' Availability.
#'
#' @param unavailTime Unavailable Time. A numeric value representing the unavailable time or a
#' numeric vector of unavailable times.
#' @param totalTime Total Time. A numeric value representing the total time for a given period
#' or a numeric vector of time periods
#' @return The function returns a numeric value representing the availability for a given period.
#' @examples
#' unavail <- 100
#' total <- 1000
#' avail(unavail, total)
#' @export
avail <- function(unavailTime, totalTime)
{
# Check for a numeric vector of unavailable times
if(all(!is.null(unavailTime), !is.numeric(unavailTime))) {
stop("Argument \"unavailTime\" must be a numeric vector")
}
# Check for a numeric vector of time periods
if(all(!is.null(totalTime), !is.numeric(totalTime))) {
stop("Argument \"totalTime\" must be a numeric vector")
}
# Calculate availability
avail <- 1 - (sum(unavailTime)/sum(totalTime))
print(avail)
}