centre | R Documentation |
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 class 'numeric'
centre(x, FUN = median, na.rm = TRUE, ...)
## S3 method for class 'factor'
centre(x, FUN, 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.
x <- c(-3, -2, 0, NA, 1, 1, 3)
centre(x) # .5 (default is median(x))
centre(x, FUN = mean) # 0
centre(x, FUN = raster::modal) # 1
y <- c(-3, -2, 0, 1, 1, 3)
y <- as.factor(y)
centre(y) # the reference level
centre(y, FUN = raster::modal) # the most frequent (modal) value
library(sf)
data(centro_2015)
centre(centro_2015$padrao) # the reference level
centre(centro_2015$padrao, FUN = raster::modal) # the most frequent value
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.