centroid {rearrr} | R Documentation |
Find the coordinates for the centroid
Description
Calculates the mean of each passed vector
/column
.
Usage
centroid(..., cols = NULL, na.rm = FALSE)
Arguments
... |
|
cols |
Names of columns to use when |
na.rm |
Whether to ignore missing values when calculating means. (Logical) |
Value
Means of the supplied vectors
/columns
. Either as a vector
or a data.frame
.
Author(s)
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
See Also
Other coordinate functions:
create_origin_fn()
,
is_most_centered()
,
midrange()
,
most_centered()
Examples
# Attach packages
library(rearrr)
library(dplyr)
# Set seed
set.seed(1)
# Create three vectors
x <- runif(10)
y <- runif(10)
z <- runif(10)
# Find centroid coordinates
# Aka. the means of each vector
centroid(x, y, z)
#
# For data.frames
#
# Create data frame
df <- data.frame(
"x" = x,
"y" = y,
"z" = z,
"g" = rep(1:2, each = 5)
)
# Find centroid coordinates
# Aka. the means of each column
centroid(df, cols = c("x", "y", "z"))
# When 'df' is grouped
df %>%
dplyr::group_by(g) %>%
centroid(cols = c("x", "y", "z"))
[Package rearrr version 0.3.4 Index]