0

I am trying to write an if statement, that translates into the following:

"If an individual's Honesty_Humility score is greater than or equal to the median Honesty_Humility score, print ('H'). If an individual's Honesty_Humility score is less than the median Honesty_Humility score, print ('L'). Since some individuals' Honesty_Humility score is missing, I want to add that if that is the case, then print ('NA')"

The code I came up with so far is the following:

for (i in 1:length(uniq)){
    dataTest$hhScore[[i]] <-
        if (Hon_Hum$Honesty_Humility[[i]] >=median(Hon_Hum$Honesty_Humility, na.rm = TRUE)){
            print ('H')
        } else if (Hon_Hum$Honesty_Humility[[i]] < median(Hon_Hum$Honesty_Humility, na.rm = TRUE)){
     print('L')
    } else {
      print('NA')
    }

}

But I keep getting this error:

Error in if (Hon_Hum$Honesty_Humility[[i]] >= median(Hon_Hum$Honesty_Humility, : missing value where TRUE/FALSE needed

Sotos
  • 51,121
  • 6
  • 32
  • 66

0 Answers0