# [R] applying a function recursively

From: Georg Otto <georg.otto_at_tuebingen.mpg.de>
Date: Wed, 11 Jun 2008 17:51:51 +0200

Hi,

```> test.list<-list("I"=list("A"=c("a", "b", "c"), "B"=c("d", "e", "f"), "C"=c("g", "h", "i")),
+                 "II"=list("A"=list("a"=c("a", "b", "c"), "b"=c("d", "e", "f"),
+                             "c"=c("g", "h", "i")),
+                   "B"=c("d", "e", "f"), "C"=c("g", "h", "i")))

```

> test.list
\$I
\$I\$A

 "a" "b" "c"

\$I\$B

 "d" "e" "f"

\$I\$C

 "g" "h" "i"

\$II
\$II\$A
\$II\$A\$a

 "a" "b" "c"

\$II\$A\$b

 "d" "e" "f"

\$II\$A\$c

 "g" "h" "i"

\$II\$B

 "d" "e" "f"

\$II\$C

 "g" "h" "i"

I would like to apply a function recursively to that list, in a way that the function does someting with each vector (eg. rev()) and returns a list of modified vectors that has the same structure as the input list, in my example:

\$I
\$I\$A

 "c" "b" "a"

\$I\$B

 "f" "e" "d"

\$I\$C

 "i" "h" "g"

\$II
\$II\$A
\$II\$A\$a

 "c" "b" "a"

\$II\$A\$b

 "f" "e" "d"

\$II\$A\$c

 "i" "h" "g"

\$II\$B

 "f" "e" "d"

\$II\$C

 "i" "h" "g"

Any hint will be appreciated.

Best,

Georg

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 11 Jun 2008 - 16:45:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 12 Jun 2008 - 13:30:43 GMT.

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