Skip to content

NA rownames in dataframes

3 messages · Yi, Derek, Brian Ripley, Peter Dalgaard

#
Hey everyone!

I am seeing strange behavior with NA in the rownames of dataframes:
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:
Error in if (missing(row.names) && (nrows[i] > 0) && (rowsi[[1]] != ""))
row.names <- data.row.names(row.names,  : 
	missing value where logical needed
Error in if (missing(row.names) && (nrows[i] > 0) && (rowsi[[1]] != ""))
row.names <- data.row.names(row.names,  : 
	missing value where logical needed
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
_                   
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:

            

  
    
#
"Yi, Derek" <Derek.Yi at FMR.COM> writes:
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...)