[R] assign object to list

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jan 20 13:10:07 CET 2006


On Fri, 20 Jan 2006, Christian Bieli wrote:

> Dear all
>
> I want to generate a list like this:
>
> a <- data.frame(1:10)
> attr(a,'myattribute') <- 'something'
> b <- data.frame(11:20)
> attr(b,'myattribute') <- 'anything'
> mylist <- list(a,b)
>
> Is there a way to place the dataframes into the list giving them the
> attribute at the same time?

Yes, the above worked.

> lapply(mylist, attributes)
> lapply(mylist, function(x) attr(x, "myattribute"))

show you they are there.

What may have confused you is that the print method for data frames does 
not show arbitrary attributes.

> I don't want to create all the dataframes in my workspace first. I tried
> it with parentheses {}, but it obviously did not work.
>
> Thanks in advance.
> Christian

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list