i have a nested list whose fundamental element is data frames, and i want to traverse this list recursively to do some computation of each data frame, finally to get a neste
Update June 2020:
You can now also use rrapply in the rrapply-package, (an extended version of base rapply). rrapply includes an additional argument dfaslist, which if set to FALSE does not treat data.frames as list-like objects by recursing into their individual columns:
library(rrapply)
L <- list(a = BOD, b = BOD)
## apply f to data.frames
rrapply(L, f = colSums, dfaslist = FALSE)
#> $a
#> Time demand
#> 22 89
#>
#> $b
#> Time demand
#> 22 89
## apply f to individual columns of data.frames
rrapply(L, f = function(x, .xname) if(.xname == "demand") scale(x) else x)
#> $a
#> Time demand
#> 1 1 -1.4108974
#> 2 2 -0.9789900
#> 3 3 0.8998070
#> 4 4 0.2519460
#> 5 5 0.1655645
#> 6 7 1.0725699
#>
#> $b
#> Time demand
#> 1 1 -1.4108974
#> 2 2 -0.9789900
#> 3 3 0.8998070
#> 4 4 0.2519460
#> 5 5 0.1655645
#> 6 7 1.0725699