[R] Can a data.frame column contain lists/arrays?

John Kane jrkrideau at yahoo.ca
Tue Feb 13 12:14:44 CET 2007


--- Christian Convey <christian.convey at gmail.com>
wrote:

> I'd like to have a data.frame structured something
> like the following:
> 
> d <- data.frame (
>    x=list( c(1,2), c(5,2), c(9,1) ),
>    y=c( 1, -1, -1)
> )
> 
> The reason is this: 'd' is the training data for a
> machine learning
> algorithm.  d$x is the independent data, and d$y is
> the dependent
> data.
> 
> In general my machine learning code will work where
> each element of
> d$x is a vector of one or more real numbers.  So for
> instance, the
> same code should work when d$x[1] = 42, or when
> d$x[1] = (42, 3, 5).
> All that matters is that all element within d$x are
> lists/vectors of
> the same length.
> 
> Does anyone know if/how I can get a data.frame set
> up like that?
> 
> Thanks,
> Christian


I doubt it.  A data.frame is a specific subset of a
list.  You should be able to do anything you want with
a list.  Have a look at the Lists and Dataframes
chapter of Intro to R.



More information about the R-help mailing list