r - lapply on each element of a list of lists -


how can perform same function (here: load.image) on each element of list of lists?

starting point list of 2 lists:

list1 <- list(c("group1", "group2", "group3")) list2 <- list(c("groupa", "groupb", "groupc")) list.all <- c(list1,list2) 

i wrote function applies lapply iteratively:

    images.list.function <- lapply(       designs.path.list,        fun = function(secondlevel.list)          lapply(secondlevel.list, function(x) load.image(x))     )     # read jpgs list     images.list <- images.list.function     images.list 

this works correctly, want format independent number of levels because in future, third or fourth level might added.

any elegant thoughts?

is useful?

flatlist = unlist(list.all) [1] "group1" "group2" "group3" "groupa" "groupb" "groupc" 

using unlist you'll end vector. use lapply image loading function.

for example, using paste function add "-image" every name:

d = lapply(flatlist, function(x){paste(x, "-image", sep = "")}) > d [[1]] [1] "group1-image"  [[2]] [1] "group2-image"  [[3]] [1] "group3-image"  [[4]] [1] "groupa-image"  [[5]] [1] "groupb-image"  [[6]] [1] "groupc-image" 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -