3

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?

2
  • 1
    How if is.null() along with some sort of an ifelse based assignment of NA? Commented Apr 13, 2016 at 17:52
  • 1
    Or, replace(x, sapply(x, is.null), "NOPE") might work Commented Apr 13, 2016 at 17:55

1 Answer 1

3

You can try:

R = 10
m = 5
lik = NULL


data.frame(R=R,
           m=m, 
           lik= if (is.null(lik)) {
               "NULL"
           } else
               lik
           )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.