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

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to