I am going through a model selection exercise where I am running a model that loops the number of parameters to add to the model. Some parameters in the model are returned as NULL meaning the model did not converge and there was some sort of problem. Obviously this is an issue. However my problem is that the NULL values wreak havoc with creating a readable dataframe. Without a dataframe that captures where the NULL values are it is difficult to troubleshoot the problem. So a long preamble to ask how do I make a returned NULL object an NA or a character NULL such that the dataframe can still be created. Here is an example:
R = 10
m = 5
lik = NULL
data.frame(R=R,
m=m,
lik=lik)
This return this error:
Error in data.frame(R = R, m = m, lik = lik) : arguments imply differing number of rows: 1, 0
I have tried using as.numeric(lik) or as.character(lik) but neither of those have produced the desired effect.
Any ideas how to deal with this?
is.null()along with some sort of anifelsebased assignment of NA?replace(x, sapply(x, is.null), "NOPE")might work