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.
'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
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With