[R] Transpose and NA's
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Mon Jul 15 11:41:44 CEST 2002
Neil Klepeis <nklepeis at uclink4.berkeley.edu> writes:
> 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
> 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"
> >
Nope. That's standard behaviour when the data frame has nonnumeric
columns. The NA constant has mode "logical" (because that mode can
always be coerced to one of the other basic modes).
> t(data.frame(x=1:10,y=1:10,z=rep(as.integer(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
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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