[R] Lists as a column in data.frame

hadley wickham h.wickham at gmail.com
Fri Sep 16 19:41:01 CEST 2005

A data frame is a list of vectors of the same length.  A list is a
vector.  So is it acceptable to use a list as a column of a data

I'd like to be able to take advantage of all the nice features of data
frames (esp. subsetting) while storing more complicated objects.  An
example of this would be a version of by that returns a data.frame
instead of a list - you would then be able to extract the objects you
wanted using subsetting, rather than having to loop through each
element of the list and see if it matches your criteria.

I have been experimenting a bit with this, and generally it works fine
(apart from the occasional bug with printing, and not being able to
use data.frame(a=1, list(a=1, b=2)) because of the way
as.data.frame.list works).  Is it ok to do this? ie. if it works in
the current version of R, should I expect it to keep working in the
future?  Is it undocumented because it is obvious, or because it's a
bad idea?



More information about the R-help mailing list