argument is of length zero

Published by onesixx on

“argument is of length zero” 

> FALSE == "turnip"
> TRUE == "turnip"
> NA == "turnip"
[1] NA
> NULL == "turnip"

As you can see, comparisons to a NULL not only don’t produce a boolean value, they don’t produce a value at all – and control flows tend to expect that a check will produce some kind of output. When they produce a zero-length output… “argument is of length zero”.

(I have a very long rant about why this infuriates me so much. It can wait.)

So, my question; what’s the output of sum(is.null(data[[k]]))? If it’s not 0, you have NULL values embedded in your dataset and will need to either remove the relevant rows, or change the check to

if(!is.null(data[[k]][[k2]]) & temp > data[[k]][[k2]]){
    #do stuff

Hopefully that helps; it’s hard to tell without the entire dataset. If it doesn’t help, and the problem is not a NULL value getting in somewhere, I’m afraid I have no idea.

Categories: Uncategorized


Blog Owner

Leave a Reply

Your email address will not be published.