Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why dim of colMeans/rowMeans return null?

Tags:

null

r

mean

I am new to R. I have the following code

sigma1  = matrix(c(2,0,0,1),2,2)
mu1     = matrix(c(0,10),2,1)

x1      = t(mvrnorm(n = 5, mu1, sigma1))

print(rowMeans(x1))
print(dim(colMeans(x1)))

and for some reason I get NULL for dimension of row/col means.

like image 328
Ash Avatar asked Dec 13 '25 18:12

Ash


1 Answers

'as.matrix' turns the vector 'colMeans(x1)' into a matrix. Then the dimensions are 5 and 1, as expected:

library(rockchalk)

sigma1  = matrix(c(2,0,0,1),2,2)
mu1     = matrix(c(0,10),2,1)
x1      = t(mvrnorm(n = 5, mu1, sigma1))

print(rowMeans(x1))
print(dim(colMeans(x1)))
print(dim(as.matrix(colMeans(x1))))

Output:

> print(rowMeans(x1))
[1] -0.1518187  9.4232239

> print(dim(colMeans(x1)))
NULL

> print(dim(as.matrix(colMeans(x1))))
[1] 5 1
> 
like image 104
mra68 Avatar answered Dec 16 '25 11:12

mra68



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!