You can directly index fields that match the logical criteria. Therefore, you can simply write:
df[is_empty(df)] = NA
Where is_empty is your comparison, for example. df == "" :
df[df == ""] = NA
But note that is.null(df) not working, and in any case will be weird 1 . However, I would advise you not to merge the logic for columns of different types! Instead, process them separately.
1 You almost never encounter NULL inside a table, since this only works if the underlying vector is list . You can create matrices and data.frames with this restriction, but then is.null(df) will never be TRUE , because NULL values ββare enclosed in a list).
source share