2
votes

I have subspace of vectors w whose elements sum to 0.

I would like to find a projection matrix Z such that it projects any x vector onto the subspace w (i.e., a subspace where the vector sums to 0).

Is there an R function to do this?

1

1 Answers

0
votes

The question did not specify how w is provided but if w is a matrix with full rank spanning the space w then

Z <- w %*% solve(crossprod(w), t(w))

If w has orthogonal columns then the above line reduces to:

Z <- tcrossprod(w)

Another possibility is to use the pracma package in which case w need not be of full rank:

library(pracma)
Z <- tcrossprod(orth(w))

If w were the space of all n-vectors that sum to zero then:

Z <- diag(n) - matrix(1, n, n) / n

Note Have revised after re-reading question.