0

So I'm trying to create a loop which reads input files based on the value present in a column 4 of my data frame.

    for (idx in 1:nrow(config_path_test)) {
         if (config_path_test[idx,2] == "ens84" & is.na(config_path_test[idx,4])) 
         {#process Raw data}

         else {
            if(config_path_test[idx,2] == "ens84" & !is.na(config_path_test[idx,4]))
              {#process TPM data}
              }

Tested my code with column 4 containing paths to my data in all fields, no paths in any of the fields or a combination of both (some have paths, some will not).

Code above deals with both all and no fields succesfully. However, for the combination of both, I'm a bit stuck.

As no paths being present is reflected for the entire column as NA, i've been using:

   is.na() and !is.na()

However, a combination of both will not show NA for the missing values. The fields are blank.

Any idea how to change my code to process the blank fields? Or any idea on how to process the blank values to NA?

Thanks in advance

TomM
  • 1
  • 1

1 Answers1

0

If I am understanding the issue correctly, the files you have read in have some ("") fields that you would like to cast to NA? If that is the case, do the following outside your function:

df[df == ""] <- NA

Do check to ensure it is not something similar, such as (" "). This thread might also be of interest to you.

Peter_Evan
  • 947
  • 10
  • 17