[R] subscripting a column from a data frame: row.names are dropped

Vadim Ogranovich vograno at arbitrade.com
Thu Nov 28 00:01:13 CET 2002


When a single column is subscripted from a data frame it doesn't inherit the
row names of the data frame. I find it surprising given the extent to which
R tries to carry names across computations. Is there a good reason for this?

Here is what I mean in details:

> y <- data.frame(a=c(1,2), b=c(1,2), row.names=c("x","y"))
y <- data.frame(a=c(1,2), b=c(1,2), row.names=c("x","y"))
> y
  a b
x 1 1
y 2 2
> y[,1]
[1] 1 2

Note that y[,1] has no names. I use R1.6.0 if it matters.


This e-mail, and any attachments thereto, is intended only for use by the
addressee(s) named herein and may contain legally privileged and/or
confidential information.  If you are not the intended recipient of this
e-mail, you are hereby notified that any dissemination, distribution or
copying of this e-mail, and any attachments thereto, is strictly prohibited.
If you have received this e-mail in error, please immediately notify me and
permanently delete the original and any copy of any e-mail and any printout

E-mail transmission cannot be guaranteed to be secure or error-free.  The
sender therefore does not accept liability for any errors or omissions in
the contents of this message which arise as a result of e-mail transmission.

NOTICE regarding privacy and confidentiality 

Knight Trading Group may, at its discretion, monitor and review the content
of all e-mail communications. 

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list