Imagine we have a foo <- function() that only takes A_Named_List_of_One_data.frame as input. For example: list(A = data.frame(d = 1:2)).
Now, imagine we have A_Named_List_of_Several_data.frames saved in object L. For example:
L = list(A = data.frame(d = 1:2), B = data.frame(d = 3:5)). So to enter L elements, we need to loop them into foo().
My understanding is that in this situation the only looping option is for as follows. Are there any other options?
output <- list() for(i in seq_along(L)) { output[[i]] <- foo(L[i]) } setNames(output, names(L)) ps. lapply enters the elements of L into foo as a data.frame while foo needs each element of L to be a A_Named_List_of_One_data.frame.
没有评论:
发表评论