[R] subscript into matrix discards row/column names

Vadim Ogranovich vogranovich at jumptrading.com
Tue Jul 21 18:46:43 CEST 2009


Dear R-help,

When the result of a matrix subscription degenerates to a scalar the names implied by the dimnames are discarded.

> x <- matrix(0, 1, 1, dimnames=list('a', 'x'))

## below I expected result to have names='x', it's not
> x[1,]
[1] 0

## below I expected result to have names='a', it's not
> x[,1]
[1] 0

This is probably a side effect of 'drop' applied to a 1*1 matrix, is there an elegant way around?

One possibility could be to allow the 'drop' arg in '[' to take numerical values (in addition to bool), which would be interpreted as dimensions to drop.

Thanks,
Vadim

Note: This email is for the confidential use of the named addressee(s) only and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you are hereby notified that any review, dissemination or copying of this email is strictly prohibited, and to please notify the sender immediately and destroy this email and any attachments.  Email transmission cannot be guaranteed to be secure or error-free.  Jump Trading, therefore, does not make any guarantees as to the completeness or accuracy of this email or any attachments.  This email is for informational purposes only and does not constitute a recommendation, offer, request or solicitation of any kind to buy, sell, subscribe, redeem or perform any type of transaction of a financial product.




More information about the R-help mailing list