On 04-Sep-09 10:45:27, Markku Karhunen wrote:
True. Should have read ?diag.
However, this provokes a more general question: Is there some way I
can declare some scalar and _all its functions_ as matrices?
For instance, I would like to
A = as.matrix(0.98)
B = function(A)
C = diag(sqrt(B))
so that all scalars are explicitly [1,1] matrices.
BR, Markku
Hmmm, it might be a good idea to explain why you want to do this.
For instance:
M <- matrix(c(1,2,3,4),nrow=2)
c <- matrix(2,nrow=1)
c%*%M
# Error in c %*% M : non-conformable arguments
c*M
# Error in c * M : non-conformable arrays
c+M
# Error in c + M : non-conformable arrays
So what would you want to use the [1,1]-matrix scalars for, that
cannot be done just using them as numbers?
Ted.
Broadly speaking, I would like to use the same code for multivariate
and univariate cases. For instance, I use the inverse Wishart
densities of MCMCpack. If I take diwish(x) of a scalar x, the
programme crashes, because diwish() by default checks
ncol(x)==nrow(x). However, I would like to have an inverse gamma
density.
Best,
Markku
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.