I’m creating empty null containers, to collect values from a "for loop".
Here is an example in my code, for which I’ve created 6 empty containers.
cont_min <- NULL
cont_max <- NULL
cont_unused <- NULL
cont_n_rec <- NULL
cont_n_don <- NULL
cont_loop_time <- NULL
I need to create quite a few of these and it’s using a lot of space using a line of code for each.
Is there a way to create multiple containers without having a separate line of code? Many thanks
>Solution :
You could use something like this:
names <- c('min', 'max', 'unused', 'n_rec', 'n_don', 'loop_time')
var_lst <- sapply(paste0('cont_', names), function(x) assign(x, NULL))
list2env(var_lst, .GlobalEnv)