Growing a list with variable names in R -



Growing a list with variable names in R -

i trying grow list in r, both value , name of each entry held in variable, doesn't seem work.

my_models_names <- names(my_models) my_rocs=list() (modl in my_models_names) { my_probs <- testpred[[modl]]$y1 my_roc <- roc(ytst, my_probs) c(my_rocs, modl=my_roc) # <-- modl , my_roc both variables }

my list my_rocs empty @ end, though know loop iterates (my_roc filled in) why?

on related note, there way without looping?

generally in r, growing objects bad. increases amount of memory used on starting total object , filling in. seems know size of list should in advance.

for example:

my_keys <- letters[1:3] mylist <- vector(mode="list", length=length(my_keys)) names(mylist) <- my_keys mylist ## $a ## null ## $b ## null ## $c ## null

you can assignment way:

key <- "a" mylist[[key]] <- 5 mylist ## $a ## [1] 5 ## ## $b ## null ## ## $c ## null

r list

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -