[R] Transpose and NA's

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Mon Jul 15 11:48:51 CEST 2002


On Sun, 14 Jul 2002, Neil Klepeis wrote:

> I noticed some odd behavior when I transpose a data frame containing
> NA's.   It seems to cast all the elements as "character" including the

You can't really transpose a data frame.  t.data.frame first coerces to a
matrix, and as your data frame has a logical column (z) it coerces to
character.  This is done by formatting the logical column, hence the
result you get.

> NA's.   Bug?
>
>  > t(data.frame(x=1:10,y=1:10,z=rep(NA,10)))
>    1      2      3      4      5      6      7      8      9      10
> x " 1"   " 2"   " 3"   " 4"   " 5"   " 6"   " 7"   " 8"   " 9"   "10"
> y " 1"   " 2"   " 3"   " 4"   " 5"   " 6"   " 7"   " 8"   " 9"   "10"
> z "  NA" "  NA" "  NA" "  NA" "  NA" "  NA" "  NA" "  NA" "  NA" "  NA"
>  >

I don't think this is a bug, but it could be done differently.
However, t() is incorrectly documented, which is a bug.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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