[R] VARIANCE across each ROW

Gabor Grothendieck ggrothendieck at gmail.com
Sun Apr 2 15:21:25 CEST 2006


Try this:

# test data
set.seed(1)
x <- matrix(rnorm(24), 6) # 6x4 matrix

sd(t(x))^2 # [1] 0.5631489 1.9047905 0.7813566 0.7415535 0.4992331 1.7095818

# same but generates an intermediate 6x6 matrix
# so less desirable if real matrix has large number of rows

diag(var(t(x))


On 4/1/06, mark salsburg <mark.salsburg at gmail.com> wrote:
> I have a very large matrix. I would like to display the variance across each
> row.
>
> In other words, I want to output a vector containing the values of variance
> across row.
>
> When I use the function var(), it seems to give me the variability of each
> column.
>
> Any ideas??




More information about the R-help mailing list