r - Using sapply(,,simplify=TRUE) -
I have a list of models and they want to return the array (not their list) Coefficient (For the inquisitive, I am running a model on data from a bunch of different neurons. I would like an array which is beneficial to x neurons.) If all the models are successfully run then the following works are fine:
cof = sapply (model list, coffee)
But if a model fails, then the coffee returns ('returns'), which returns to other return values Has a different length, and I have a list with an array instead ends. : (
My solution works and is general purpose, but it is extremely ruthless:
coff = sapply (model list, coffee) normal = cof [ 1]] # (It should be sure that this is not zero!) Typical [1: length (typical)] = NA # Change all coefficients with bad bad = sapply (modellist, is.null) # #) # For each 'zero', (yug! A loop!) Coffs [[i]] = with a proper entry (nas) coheas = selifiser 2 (kofes) = instead of # typical # now i have an array Switch to be able to convert Am
There is no better solution?
Thank you!
Lari
Still a little irritant:
< Code> sapply (model list, function (x) ifelse (is.null (coef (x)), na, coef (x))
Comments
Post a Comment