I have a list of columns within a dataframe which where i want to check if all those columns are NA
and create a new column which tells me if they are NA
or not.
Here is an example of it working with one column, where Any_Flag
is my new column:
ItemStats_2014$Any_Flag <- ifelse(is.na(ItemStats_2014$Item_Flag_A), "Y", "N")
When i try to run the check over multiple columns, I am getting what i expect:
ItemStats_2014$Any_Flag <- ifelse(all(is.na(ItemStats_2014[ ,grep("Flag", names(ItemStats_2014), value = T)])), "Y", "N")
It returns everything to be false or "N".