I need to generate many (100k order) random vectors of variable sizes such that:
sum(v_i)=0
and sum(v_i^2)=1
sum up to zero and the sum of the squares is one, for each vector.
This is the code I write:
c1 <- rnorm(ki[i])
c1 <- c1-mean(c1)
e1 <- c1/sqrt(sum(c1^2))
Where e1
is the final vector I need: sum(e1)=0
and sum(e1^2)=1
Is it possible to speed up this generation?