Learn R Programming

rchemo (version 0.1-3)

aggmean: Centers of classes

Description

Calculation of the centers (means) of classes of row observations of a data set.

Usage

aggmean(X, y = NULL)

Value

ct

centers (column-wise means)

lev

classes

ni

number of observations in each per class

Arguments

X

Data (\(n, p\)) for which are calculated the centers (column-wise means).

y

Class membership (\(n, 1\)) of the row of X. Default to NULL (all the rows of are considered).

Examples

Run this code

n <- 8 ; p <- 6
X <- matrix(rnorm(n * p, mean = 10), ncol = p, byrow = TRUE)
y <- sample(1:2, size = n, replace = TRUE)
aggmean(X, y)

data(forages)
Xtrain <- forages$Xtrain
ytrain <- forages$ytrain
table(ytrain)
u <- aggmean(Xtrain, ytrain)$ct
headm(u)
plotsp(u, col = 1:4, main = "Means")
x <- Xtrain[1:20, ]
plotsp(x, ylab = "Absorbance", col = "grey")
u <- aggmean(x)$ct
plotsp(u, col = "red", add = TRUE, lwd = 2)

Run the code above in your browser using DataLab