Hello William,

that's exactly what I needed. I didn't consider lapply'ing over
seq_along(data) instead of data, very useful.

Thanks a lot!

Giovanni

On Mon, Aug 14, 2017 at 10:02 PM, William Dunlap <wdun...@tibco.com> wrote:
> You could replace your 'depth' argument with one that shows where in the
> original data you are at:
>
> leaf.func <-
> function(data, where) {
>         if(is.null(data)) stop("Null data at ", deparse(where))
>         return(mean(data))
> }
> visit.level <-
> function(data, where = integer()) {
>         if (length(where) == 2) {
>                 return(leaf.func(data, where))
>         } else {
>                 res <- lapply(seq_along(data), function(i)
> visit.level(data[[i]], where = c(where, i)))
>                 names(res) <- names(data)
>                 return(res)
>         }
> }
>
> E.g.,
>> new.data <- visit.level(data, integer())
> Error in leaf.func(data, where) : Null data at c(3L, 2L)
>> data[[3]][2]
> $Madrid
> NULL

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to