[R] assign object to list

Jacques VESLOT jacques.veslot at cirad.fr
Fri Jan 20 13:13:09 CET 2006

if you have a list of data frames without the attribute and a 
vector/list of the values for this attributes:

mapply(function(x,y) {attr(x,"names") <- y ; x},
    list(data.frame(1:10), data.frame(11:20)), c("something", 
"anything"), SIMPLIFY=F)

Christian Bieli a écrit :

>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?
>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.

More information about the R-help mailing list