[R] rbind'ing empty rows in dataframes in 1.4.1 versus 1.5.0

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Apr 30 17:40:53 CEST 2002


"David Kane  <David Kane" <a296180 at mica.fmr.com> writes:

> This does not work in 1.5.0
> 
> > x <- data.frame(a = letters[1:3], b = 1:3)
> > x
>   a b
> 1 a 1
> 2 b 2
> 3 c 3
> > x[4,]
>         a  b
> <NA>     <NA> NA
> > rbind(x, x[4,])
> Error in if (nrow > 0 && all(ri == 1:ni)) seq(from = nrow + 1, length = ni) else ri : 
> 	missing value where logical needed
> > R.version
...
> Note that, contrary to my first guess, this has nothing (?) to do with the new
> NA in character vectors since I see the same behavior with numeric only
> dataframes.
...
> I didn't see anything in the NEWS about this change. Could someone please
> explain what is going one? Any words of wisom about the "right" way to create
> empty rows in dataframe (which I then fill in variable by variable later in the
> program) would also be appreciated.

We can't anticipate *everything* that people will try to do...

I bet the behaviour has to do with new NA in *rownames*. You could try
inserting a meaningful name. It probably counts as a bug:

> airquality[as.numeric(NA),]
     Ozone Solar.R Wind Temp Month Day
<NA>      NA      NA   NA   NA    NA  NA
> airquality[rep(as.numeric(NA),7),]
    Ozone Solar.R Wind Temp Month Day
NA     NA      NA   NA   NA    NA  NA
NA1    NA      NA   NA   NA    NA  NA
NA2    NA      NA   NA   NA    NA  NA
NA3    NA      NA   NA   NA    NA  NA
NA4    NA      NA   NA   NA    NA  NA
NA5    NA      NA   NA   NA    NA  NA
NA6    NA      NA   NA   NA    NA  NA

> airquality[c(1,NA),]
     Ozone Solar.R Wind Temp Month Day
<NA>      NA      NA   NA   NA    NA  NA

Notice that it is only when there's a single NA row that we see the problem.
-- 
   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