[R] lapply and list attributes

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Mar 10 16:44:36 CET 2006


michael watson (IAH-C) wrote:

> Hi
> 
> I have a list that has attributes:
> 
> attributes(lis[2])
> $names
> [1] "150096_at"


Here you get the attributes of "lis", while you will get the attributes 
of the *elements* of "lis" when applying the functions below, the lattes 
is comparable with
  attributes(lis[[2]])

Uwe Ligges



> I want to use those attributes in a function and then use lapply to
> apply that function to every element of the list, eg for simplicity's
> sake:
> 
> my.fun <- function(x) {
>         attributes(x)
> }
> 
> Then
> 
> l2 <- lapply(lis, my.fun)
> 
> It seems that "attributes(x)" within the function is not the same as eg.
> "attributes(lis[2])" used outside of the function, ie the attributes
> have changed.
> 
> Help for someone who's trying to understand lists?
> 
> Many thanks
> Mick 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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




More information about the R-help mailing list