-- Bert
On Wed, Oct 10, 2012 at 11:22 PM, Herv? Pag?s <hpages at fhcrc.org> wrote:
Hi,
Two ways to create what should normally be the same data frame:
df1 <- data.frame(a=character(0), b=character(0))> df1
[1] a b
<0 rows> (or 0-length row.names)
df2 <- as.data.frame(matrix(character(0), ncol=2, dimnames=list(NULL,
[1] a b
<0 rows> (or 0-length row.names)
unique() works as expected except that I get a warning on 'df2':
[1] a b
<0 rows> (or 0-length row.names)
[1] a b
<0 rows> (or 0-length row.names)
Warning message:
In is.na(rows) : is.na() applied to non-(list or vector) of type 'NULL'
Look like the two data frames are not identical:
[1] "Attributes: < Length mismatch: comparison on first 1 components >"
$names
[1] "a" "b"
$row.names
integer(0)
$class
[1] "data.frame"
$names
[1] "a" "b"
$class
[1] "data.frame"
Actually 'df2' is considered broken by validObject():
Error in validObject(df2) :
invalid class ?data.frame? object: slots in class definition but not in
object: "row.names"
This is with R 2.15 and recent R devel.
Cheers,
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