[R] A data.frame is also a list [was "... reading in columns ..."]

Martin Maechler maechler at stat.math.ethz.ch
Fri Apr 28 09:21:14 CEST 2000

>>>>> "Faheem" == Faheem Mitha <faheem at email.unc.edu> writes:

    Faheem> Just to make sure I understand this. lapply acts on lists.  In
    Faheem> the line below, are we regarding mydat[ ,1:66] as a list with
    Faheem> 66 components?  How is lapply happy to regard this as a list?
    Faheem> I have only the dimmest understanding of how classes are
    Faheem> inherited by subsets of objects, but class(mydat[ ,1:66]) gives
    Faheem> data.frame, and is a data frame also a list?


?data.frame contains
>> Description:
>>      These functions create or manipulate data frames, tightly coupled
>>      collections of variables which share many 
>>      of the properties of matrices and of lists, .....
	                     ^^^^^^^^ ---    ^^^^^

Maybe the following is revealing 
[unclass() just strips the "class" attribute]:

  > str(unclass(data.frame(x=1:2,y=c("a","b"))))
  List of 2
   $ x: int [1:2] 1 2
   $ y: Factor w/ 2 levels "a","b": 1 2
   - attr(*, "row.names")= chr [1:2] "1" "2"

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