I have a Dataframe in R where certain rows in some of the columns have values that are NA
or empty strings \"\"
. I want to convert these to NULL<
There really is no NULL value in a vector. NA is the placeholder. If you want to remove the entire column (which is what assigning NULL would do) when its values are all NA then this would succeed:
df[ , sapply(df, function(x) all(is.na(x)) ) ] <- NULL
If you want to construct an object where you keep only those rows with no NA values:
df[ apply(df,1, function(rw) !any(is.na(rw)) ) , ]