vendredi 3 septembre 2021

R using any() function within if raises an error

I was working with a dataset where within final_source_list, source is a character column and quantity is a double column. Below is a code that I used to print a statement based on certain conditions. However, please note that I used many if conditionals but this is only a part of it.

When I run this code, I get an error saying that the conditional part supplied a NA instead of TRUE/FALSE. But when I run the conditional part individually, I do get TRUE/FALSE. Can someone help what the reason of this error.

for (i in final_source_list_df$sources) {
  if (final_source_list_df[(final_source_list_df$sources == i), "quantity"] < 1000) {
    if ((any(df_201304$sources == i) &
         any(df_20217$sources == i))) { print("Elite resource") } } } 

Aucun commentaire:

Enregistrer un commentaire