R/helpers.R
centre.Rd
Return the median value or the modal value of a vector, depending on whether the vector is numeric or a factor.
centre(x, ...) # S3 method for numeric centre(x, na.rm = TRUE, ...) # S3 method for factor centre(x, na.rm = TRUE, ...)
x | an object for which a method has been defined, or a numeric vector containing the values whose median is to be computed. |
---|---|
... | potentially further arguments for methods; not used in the default method. |
na.rm | a logical value indicating whether |
the median value for objects of the class integer or double. The modal value for objects of class factor.
vec <- c(-3, -2, 0, 1, 1, 3) centre(vec)#> [1] 0.5vec <- c(-3, -2, 0, 1, 1, 3) vec <- as.factor(vec) centre(vec)#> [1] 1 #> Levels: -3 -2 0 1 3centre(itacorubi_2015@data$padrao)#> [1] medio #> Levels: baixo medio alto