Skip to content
Browse files

resolution: if input is integer, return 1

If the input is an integer, this means that it represents a discrete variable,
where the resolution is 1. Fixes #629
  • Loading branch information...
1 parent 84a21cf commit b7fa3187371432d062d6d760cc0c72330d0a9a0d @wch wch committed Aug 17, 2012
Showing with 11 additions and 1 deletion.
  1. +6 −1 R/utilities-resolution.r
  2. +5 −0 man/resolution.Rd
View
7 R/utilities-resolution.r
@@ -4,6 +4,9 @@
#' values. If there is only one unique value, then the resolution is defined
#' to be one.
#'
+#' If x is an integer vector, then it is assumed to represent a discrete
+#' variable, and the resolution is 1.
+#'
#' @param x numeric vector
#' @param zero should a zero value be automatically included in the
#' computation of resolution
@@ -13,8 +16,10 @@
#' resolution((1:10) - 0.5)
#' resolution((1:10) - 0.5, FALSE)
#' resolution(c(1,2, 10, 20, 50))
+#' resolution(as.integer(c(1, 10, 20, 50))) # Returns 1
resolution <- function(x, zero = TRUE) {
- if (zero_range(range(x, na.rm = TRUE))) return(1)
+ if (is.integer(x) || zero_range(range(x, na.rm = TRUE)))
+ return(1)
x <- unique(as.numeric(x))
if (zero) {
View
5 man/resolution.Rd
@@ -15,10 +15,15 @@
between adjacent values. If there is only one unique
value, then the resolution is defined to be one.
}
+\details{
+ If x is an integer vector, then it is assumed to
+ represent a discrete variable, and the resolution is 1.
+}
\examples{
resolution(1:10)
resolution((1:10) - 0.5)
resolution((1:10) - 0.5, FALSE)
resolution(c(1,2, 10, 20, 50))
+resolution(as.integer(c(1, 10, 20, 50))) # Returns 1
}

0 comments on commit b7fa318

Please sign in to comment.
Something went wrong with that request. Please try again.