I declared a 1 by 6 matrix A by saying:
A <- matrix(1:6, nrow=1)
I then do dim(A) and as expected I get 1 by 6…but then I do A[,2:5] and I would expect that to be a matrix of dimension 1 by 4 with entries 2,3,4,5…but instead dim( A[,2:5] ) gives me NULL! it degraded into a vector or something. How can I avoid this?
I am ultimately trying to do something like:
A[,a:b] %*% X[a:b,a:b] %*% t(A[,a:b])
varying a and b so I can multiply only parts of the above matrices together..but this breaks when A decays into a vector…
Thanks
Use
,drop=FALSEas an additional (trailing) argument to involving].Example:
This may well be the main FAQ, but for compatibility reasons the behaviour is unlikely to change.