I have a dataframe, books
, and I'm trying to loop through all columns and return something like missing
if that column has any missing values.
Below is my code. It returns what elements are missing. I then check if TRUE
makes up any of those elements, suggesting that that is a missing element.
This works.
However, being new to R, I know there are better ways of doing this that I'm unaware of.
for (col in colnames(books)) {
bool <- is.na(books[[col]])
if (TRUE %in% bool) {
print("Missing")
} else {
print("Fine")
}
}