Re: [R] apply a function to several lists' components

From: JeeBee <JeeBee_at_troefpunt.nl>
Date: Sat 01 Jul 2006 - 04:01:40 EST

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


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 Sat Jul 01 04:06:02 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 01 Jul 2006 - 06:14:18 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.