Re: [R] assign object to list

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 20 Jan 2006 - 23:10:07 EST

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@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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Jan 20 23:27:12 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:07 EST