Hey everyone! I am seeing strange behavior with NA in the rownames of dataframes:> a <- data.frame(1:3, row.names = c("r1", NA, "r3")) > cbind(a)X1.3 r1 1 <NA> 2 r3 3 Everything works. The peculiar thing is that when the NA is in the first row, things no longer work as I would have expected:> b <- data.frame(1:3, row.names = c(NA, "r2", "r3")) > cbind(b)Error in if (missing(row.names) && (nrows[i] > 0) && (rowsi[[1]] != "")) row.names <- data.row.names(row.names, : missing value where logical needed> data.frame(b)Error in if (missing(row.names) && (nrows[i] > 0) && (rowsi[[1]] != "")) row.names <- data.row.names(row.names, : missing value where logical needed> traceback()3: data.frame(..., check.names = FALSE) 2: cbind(...) 1: cbind(b) This seems to be a problem associated only with dataframes, as a similar example using matrices works perfectly fine. Has anyone experienced this behavior before? Thanks! Derek> R.version_ platform sparc-sun-solaris2.6 arch sparc os solaris2.6 system sparc, solaris2.6 status major 1 minor 5.1 year 2002 month 06 day 17 language R -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
It's a bug in data.frame. You should not be allowed NA rownames. Solution: don't specify them. I'll add a test for 1.6.0. On Wed, 28 Aug 2002, Yi, Derek wrote:> Hey everyone! > > I am seeing strange behavior with NA in the rownames of dataframes: > > > a <- data.frame(1:3, row.names = c("r1", NA, "r3")) > > cbind(a) > X1.3 > r1 1 > <NA> 2 > r3 3 > > Everything works. The peculiar thing is that when the NA is in the first > row, things no longer work as I would have expected: > > > b <- data.frame(1:3, row.names = c(NA, "r2", "r3")) > > cbind(b) > Error in if (missing(row.names) && (nrows[i] > 0) && (rowsi[[1]] != "")) > row.names <- data.row.names(row.names, : > missing value where logical needed > > data.frame(b) > Error in if (missing(row.names) && (nrows[i] > 0) && (rowsi[[1]] != "")) > row.names <- data.row.names(row.names, : > missing value where logical needed > > > traceback() > 3: data.frame(..., check.names = FALSE) > 2: cbind(...) > 1: cbind(b) > > This seems to be a problem associated only with dataframes, as a similar > example using matrices works perfectly fine. Has anyone experienced this > behavior before? > > Thanks! > > Derek > > > R.version > _ > platform sparc-sun-solaris2.6 > arch sparc > os solaris2.6 > system sparc, solaris2.6 > status > major 1 > minor 5.1 > year 2002 > month 06 > day 17 > language R > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"Yi, Derek" <Derek.Yi at FMR.COM> writes:> > data.frame(b) > Error in if (missing(row.names) && (nrows[i] > 0) && (rowsi[[1]] != "")) > row.names <- data.row.names(row.names, : > missing value where logical needed > > > traceback() > 3: data.frame(..., check.names = FALSE) > 2: cbind(...) > 1: cbind(b) > > This seems to be a problem associated only with dataframes, as a similar > example using matrices works perfectly fine. Has anyone experienced this > behavior before?Not to my knowledge, on this list, anyway. However, it looks like a fairly clear bug. I think you want ... && !(rowsi[[1]] %in% "") in the relevant line about two-thirds through data.frame(). Character NA's (as opposed to the string "NA") are a relatively new invention, and oversights like this are bound to happen. (NA rownames are generally a bad idea, though...) -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Apparently Analagous Threads
- Misalignment of <NA> in rownames (PR#1905)
- Non-alignment of <NA> in rownames
- row.names(data.frame(matrixWithDimnames)) depends on first rowname being "" or not. (PR#13230)
- Suppressing "creating new generic" and "expanding the signature" messages
- Sourcing files with library