I have a list of elements where the number of elements is not fixed. I would like to name the element automatically based on their number. For example, if the list contains 9
, then I would like to give names for the nine elements, as Model_1
, Model_2
, and so on. If the number of the element is changed, then, I do not need to change it manually.
For example, in the following code, the name of the elements must be done manually.
names1 <- c("1","2", "3", "4", "5", "6", "7", "8", "9")
lapply(setNames(unlist(myres), paste0(names1, '_Model')), function(x)
setNames(x, paste0('Res_', seq_along(x))))
Is there an automatic way to set the names of the elements which are not fixed?