I am trying to see if the data.frame column has any null values to move to the next loop. I am currently using the code below:
if (is.na(df[,relevant_column]) == TRUE ){next}
which spits out the warning:
In if (is.na(df_cell_client[, numerator]) == TRUE) { ... : the condition has length > 1 and only the first element will be used
How do I check if any of the values are null and not just the first row?
(I assume by "null" you really mean NA
, since a data.frame cannot contain NULL
in that sense.)
Your problem is that if
expects a single logical, but is.na(df[,relevant_column])
is returning a vector of logicals. any
reduces a vector of logicals into a single global "or" of the vector: Try:
if (any(is.na(df[,relevant_column]))) {next}
BTW: == TRUE
is unnecessary. Keep it if you feel you want the clarity in your code, but I think you'll find most R code does not use that. (I've also seen something == FALSE
, equally "odd/wrong", where ! something
should work ... but I digress.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.