centr | R Documentation |
Calculation of the centers (eg. mean or median) of classes of row observations of a data set.
centr(X, Y = NULL, FUN = mean, ...)
X |
A |
Y |
A vector of length |
FUN |
The function used in the aggregation (Default to mean). |
... |
Optionnal arguments to pass in the function defined in |
centr
uses function aggregate
.
A list of outputs.
n <- 8
p <- 6
set.seed(1)
X <- matrix(rnorm(n * p, mean = 10), ncol = p, byrow = TRUE)
y <- sample(1:2, size = n, replace = TRUE)
set.seed(NULL)
centr(X, y)
centr(X, y, FUN = median)
data(datforages)
Xr <- datforages$Xr
yr <- datforages$yr
table(yr)
u <- centr(Xr, yr)$centers
v <- centr(Xr, yr, FUN = median)$centers
headm(u)
headm(v)
oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(1, 2))
plotsp(u, col = 1:4, main = "Mean")
plotsp(v, col = 1:4, main = "Median")
par(oldpar)
x <- Xr[1:20, ]
plotsp(x, ylab = "Absorbance", col = "grey")
u <- centr(x)$centers
plotsp(u, col = "red", add = TRUE, lwd = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.