[Bioc-devel] rbind,DataFrame vs rbind.data.frame

Hervé Pagès hpages at fhcrc.org
Wed Apr 30 08:24:03 CEST 2014


Hi Michael,

I noticed this difference between DataFrame vs data.frame when doing
rbind():

   > rbind(data.frame(aa=NA), data.frame(aa=1:2))
     aa
   1 NA
   2  1
   3  2

   > rbind(DataFrame(aa=NA), DataFrame(aa=1:2))
   DataFrame with 4 rows and 1 column
            aa
     <logical>
   1        NA
   2      TRUE
   3      TRUE

If the DataFrame with NAs is put after the DataFrame with integers,
things look better:

   > rbind(DataFrame(aa=1:3), DataFrame(aa=NA))
   DataFrame with 4 rows and 1 column
            aa
     <integer>
   1         1
   2         2
   3         3
   4        NA

As a consequence, combining 2 Vector objects, one with no metadata cols
and one with metadata cols, will loose the data if the object with no
metadata cols is put first:

   ir1 <- IRanges(1:2, 5)
   ir2 <- IRanges(11:13, 14)
   mcols(ir2) <- DataFrame(score=2:0)

Then:

   > mcols(c(ir1, ir2))
   DataFrame with 5 rows and 1 column
         score
     <logical>
   1        NA
   2        NA
   3      TRUE
   4      TRUE
   5     FALSE

How hard it would be to bring the rbind,DataFrame method in line with
rbind.data.frame?

Thanks,
H.

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



More information about the Bioc-devel mailing list