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" > -- ______________________________________________________ Neil E. Klepeis, UC Berkeley, School of Public Health, and Lawrence Berkeley National Laboratory, Berkeley, CA USA. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 theYou 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._