I have this kind of situation
list1 = list(mtcars, airquality, mtcars, airquality)
combined_list = list(list1, list1)
names(combined_list) = c('A_B','S_D')
combined_list = lapply(combined_list, function(x)
setNames(x, c(rep('something', 2), rep('gotta give',2))))
and for each of the step here presented, I would like to learn how to add to each element of the with the same name, respectively the first and the second element separated from the underscore, which is named the first list with
This means for example to obtain for list[[1]] = A_B`
something_A
something_B
gotta give_A
gotta give_B
list[[2]] = S_D
something_S
something_D
gotta give_S
gotta give_D
I am trying something like this to generate the name but it does not follows the desired sequence
lapply(seq(1:2), function(i) {lapply(seq(1:2), \(j)
c(paste0(rep('something', 2), strsplit(names(combined_list), '_')[[j]][i]),
paste0(rep('gotta give',2), strsplit(names(combined_list), '_')[[j]][i])))})
You can use
LETTERSandpaste()to generate names forsetNames()Output: