[R] apply a function to several lists' components
JeeBee
JeeBee at troefpunt.nl
Fri Jun 30 20:01:40 CEST 2006
Maybe this helps
( data1 = list(a=c(1,2), b=c(3,4), c=c(5,6,7)) )
( data2 = list(a=c(10,11), b=c(30,40), c=c(70,80)) )
cc <- NULL
for(data in ls(pattern="^data[0-9]+$")) {
cc <- c(cc, with(get(data), c))
}
mean(cc)
JeeBee.
On Fri, 30 Jun 2006 09:50:51 -0500, Taka Matzmoto wrote:
> Dear R-user
> I have 100 lists.
> Each list has several components.
> For example,
>
>>data1
> $a
> [1] 1 2
>
> $b
> [1] 3 4
>
> $c
> [1] 5
>
> There are data1, data2,...., data100. All lists have the same number and the
> same name of components.
>
>
> Is there any function I can use for applying to only a specific component
> across 100 lists?
> (e.g., taking mean of $c acorss 100 lists) or do I need to write my own
> function for that?
>
> Thank you.
>
> Taka,
>
> ______________________________________________
> 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