From hpages at fredhutch.org  Fri Jun 10 23:22:22 2016
From: hpages at fredhutch.org (=?UTF-8?B?SGVydsOpIFBhZ8Oocw==?=)
Date: Fri, 10 Jun 2016 14:22:22 -0700
Subject: [Rd] as.array() on a data.frame
Message-ID: <575B2F8E.8030500@fredhutch.org>

Wouldn't it make sense to have as.array() work on a data.frame and
be equivalent to as.matrix()?

   df <- data.frame(stuff=1:3)

   # as.matrix(df)
   #      stuff
   # [1,]     1
   # [2,]     2
   # [3,]     3

   as.array(df)
   # Error in `dimnames<-.data.frame`(`*tmp*`, value = list(n)) :
   #   invalid 'dimnames' given for data frame

Note that as.array() actually works on a 0-col data.frame but
seems broken (it returns a data.frame instead of an array):

   as.array(df[0])
   # data frame with 0 columns and 3 rows

FWIW the returned data.frame is an invalid object:

   attributes(as.array(df[0]))
   # $row.names
   # [1] 1 2 3
   #
   # $class
   # [1] "data.frame"
   #
   # $dim
   # [1] 0

   validObject(as.array(df[0]))
   # Error in validObject(as.array(df[0])) :
   #   invalid class ?data.frame? object: slots in class definition but
   #   not in object: "names"

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 fredhutch.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



[Rd] as.array() on a data.frame
=?UTF-8?B?SGVydsOpIFBhZ8Oocw==?=